Skip to content

Fix encoding error (python 3) - #141

Merged
sylvinus merged 1 commit into
pricingassistant:masterfrom
Serenytics:master
Dec 13, 2016
Merged

Fix encoding error (python 3)#141
sylvinus merged 1 commit into
pricingassistant:masterfrom
Serenytics:master

Conversation

@achauve

@achauve achauve commented Dec 13, 2016

Copy link
Copy Markdown
Contributor

BTW we now use MRQ successfully in production with python 3.5.2 at Serenytics :)
Thanks again @sylvinus for sharing this lib!

@sylvinus

Copy link
Copy Markdown
Contributor

Yay! :)

@sylvinus
sylvinus merged commit 84faf4a into pricingassistant:master Dec 13, 2016
@skuda

skuda commented Dec 21, 2016

Copy link
Copy Markdown

This breaks using Python2, we had problems with that key for example:

In [20]: key = "XZ{Z\x0f\x96\xbcr\xea\xbdm\r"

In [21]: binascii.hexlify(key)
Out[21]: '585a7b5a0f96bc72eabd6d0d'

In [22]: binascii.hexlify(key.encode('utf-8') if isinstance(key, str) else key)
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-22-25b650f21318> in <module>()
----> 1 binascii.hexlify(key.encode('utf-8') if isinstance(key, str) else key)

UnicodeDecodeError: 'ascii' codec can't decode byte 0x96 in position 5: ordinal not in range(128)

isinstance(key, str) means something different in Python3 and Python2, being unicode in Python 3 but bytes in Python2. maybe a check for sys.version_info < (3,) is needed?

@achauve

achauve commented Dec 21, 2016

Copy link
Copy Markdown
Contributor Author

Indeed the isinstance(key, str) is okay in python2 only if we use the str builtin from future:

from builtins import str

@achauve achauve mentioned this pull request Dec 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants