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

Problem in _setup() on non-English OS #346

Closed
pochamarui opened this issue Aug 11, 2020 · 6 comments · Fixed by #359
Closed

Problem in _setup() on non-English OS #346

pochamarui opened this issue Aug 11, 2020 · 6 comments · Fixed by #359
Labels

Comments

@pochamarui
Copy link

pochamarui commented Aug 11, 2020

There's a problem in that code in 1.2.6:

 def _warn_import_error(exc):
        [...]
        _warn("ImportError: %s" % msg)

The _warn() call will throw a unicode-decode-error when run on a french OS, for instance:
<type 'exceptions.UnicodeDecodeError'> 'ascii' codec can't decode byte 0xe9 in position 59: ordinal not in range(128)

Possibly a missing .encode('utf-8') on msg?

@mottosso mottosso added the bug label Aug 11, 2020
@mottosso
Copy link
Owner

Thanks for reporting this @pochamarui!

I wonder, can it be as easy as putting this line at the top of the Qt.py Python file?

# -*- coding: utf-8 -*-

@pochamarui
Copy link
Author

I don't have access to that machine at the moment, so I cannot currently test, but I think it will not work.

By the look of it, that string above is used so that unicode strings - written inside the python source file - can be handled correctly. In my case, the string is not in the source file, but returned by the OS.
It is part of the exception, and is not stored in the .py file

@mottosso
Copy link
Owner

Cool, no worries. Are you able to post the message here? I need some way of reproducing the error, ideally during the automated tests.

@pochamarui
Copy link
Author

pochamarui commented Aug 12, 2020

I asked a colleague with a French machine to do a few tests.
The error-message (obtained by writing it to a text file), is:

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

Side-notes:

  • isinstance(msg, str)
    returns true

  • attempting to encode/decode msg to utf-8 , before passing it to warn(), failed

@friedererdmann
Copy link
Contributor

Hey, ran into this today. I'm proposing the following:

def _setup(module, extras):
    """Install common submodules"""
    Qt.__binding__ = module.__name__

    def _warn_import_error(exc):
        if sys.version_info < (3, 0):
            if isinstance(exc, unicode):
                exc = exc.encode('ascii', 'replace')
        msg = str(exc)
        if "No module named" in msg:
            return
        _warn("ImportError: %s" % msg)

[...]

I can only see the issue in Python 2, therefore the version check.
You can test the 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.'

@mottosso
Copy link
Owner

mottosso commented Jul 8, 2021

Seems good to me. Could you put it in a PR?

mottosso added a commit that referenced this issue Jul 8, 2021
Unicode encoding in import errors - Fix for issue #346
@mottosso mottosso closed this as completed Jul 8, 2021
mottosso added a commit that referenced this issue Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants