Skip to content

Commit

Permalink
[sffbase] Make convert_hex_to_string() compatible with both Python 2 …
Browse files Browse the repository at this point in the history
…and Python 3 (#165)

When called with Python 3, `str.strip(binascii.unhexlify(ret_str))` will raise an exception: ` descriptor 'strip' requires a 'str' object but received a 'bytes'`. This patch (`binascii.unhexlify(ret_str).decode("utf-8").strip()`) will work properly with both Python 2 and Python 3.

Fixes sonic-net/sonic-platform-common#160
  • Loading branch information
jleveque committed Feb 10, 2021
1 parent bd4dc03 commit 513920c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sonic_platform_base/sonic_sfp/sffbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def convert_hex_to_string(self, arr, start, end):
ret_str = ''
for n in range(start, end):
ret_str += arr[n]
return str.strip(binascii.unhexlify(ret_str))
return binascii.unhexlify(ret_str).decode("utf-8").strip()
except Exception as err:
return str(err)

Expand Down

0 comments on commit 513920c

Please sign in to comment.