Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode encoding in import errors - Fix for issue #346 #357

Merged
merged 6 commits into from
Jul 8, 2021

Conversation

friedererdmann
Copy link
Contributor

If Python 2, and import error message is unicode, encode as ascii before casting to string to avoid UnicodeDecodeError.

Fix for #346

Typical example of error message that triggers a UnicodeDecodeError:

DLL load failed : le module spécifié est introuvable.

Typical use case where this happens:

French Windows language and trying to use Qt.py in application with Python 2 and unicode strings.

Isolated behavior:

import sys
text = str(u"DLL load failed : le module spécifié est introuvable.".encode('ascii', 'replace'))
>> b'DLL load failed : le module sp?cifi? est introuvable.'

Encoding unicode to ascii with replace if Python 2 before casting it to string to avoid UnicodeDecodeError
encoding unicode to ascii in warn_import_error
@CLAassistant
Copy link

CLAassistant commented Jul 8, 2021

CLA assistant check
All committers have signed the CLA.

Qt.py Outdated Show resolved Hide resolved
Added definition of unicode for Python 3 as Hound was flagging it otherwise. (Change doesn't do anything in Python 3 otherwise).
@mottosso
Copy link
Owner

mottosso commented Jul 8, 2021

This looks good, thanks for this. Now, can you think of any way to actually test this? :S Ideally, we'd run it on a non-English OS, but in the context of Travis I'm not sure how to do that..

Also, I just noticed Travis isn't even being called! Investingating..

@mottosso
Copy link
Owner

mottosso commented Jul 8, 2021

There we go, looks like there's another complaint regarding the unicode variable.

@mottosso
Copy link
Owner

mottosso commented Jul 8, 2021

Looks good, let's give it a try!

@mottosso mottosso merged commit 60fc345 into mottosso:master Jul 8, 2021
@friedererdmann friedererdmann mentioned this pull request Jul 13, 2021
mottosso added a commit that referenced this pull request Jul 16, 2021
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.

None yet

4 participants