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

import _curses fails because of UnicodeDecodeError('utf8' codec can't decode byte 0xb5 ...') on ARM Ubuntu 3.x #57781

Closed
vstinner opened this issue Dec 10, 2011 · 13 comments
Labels
stdlib Python modules in the Lib dir topic-unicode

Comments

@vstinner
Copy link
Member

BPO 13572
Nosy @warsaw, @brettcannon, @vstinner, @ezio-melotti, @serhiy-storchaka
Files
  • curses_getkey_utf8_surrogateescape.patch
  • curses_getkey_latin1.patch
  • curses_getkey_locale.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-11-17.22:40:13.573>
    created_at = <Date 2011-12-10.13:47:28.423>
    labels = ['library', 'expert-unicode']
    title = "import _curses fails because of UnicodeDecodeError('utf8' codec can't decode byte 0xb5 ...') on ARM Ubuntu 3.x"
    updated_at = <Date 2012-11-17.22:40:13.572>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2012-11-17.22:40:13.572>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-11-17.22:40:13.573>
    closer = 'vstinner'
    components = ['Library (Lib)', 'Unicode']
    creation = <Date 2011-12-10.13:47:28.423>
    creator = 'vstinner'
    dependencies = []
    files = ['27595', '27596', '27597']
    hgrepos = []
    issue_num = 13572
    keywords = ['patch']
    message_count = 13.0
    messages = ['149155', '149156', '149158', '149201', '149266', '149314', '171756', '171759', '173065', '173070', '173099', '175770', '175819']
    nosy_count = 5.0
    nosy_names = ['barry', 'brett.cannon', 'vstinner', 'ezio.melotti', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue13572'
    versions = ['Python 3.3']

    @vstinner
    Copy link
    Member Author

    http://www.python.org/dev/buildbot/all/builders/ARM%20Ubuntu%203.x/builds/143/steps/test/logs/stdio
    ---

    test test_curses crashed -- Traceback (most recent call last):
      File "/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Lib/test/regrtest.py", line 1214, in runtest_inner
        the_package = __import__(abstest, globals(), locals(), [])
      File "/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Lib/test/test_curses.py", line 23, in <module>
        curses = import_module('curses')
      File "/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Lib/test/support.py", line 105, in import_module
        return importlib.import_module(name)
      File "/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Lib/importlib/__init__.py", line 123, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Lib/importlib/_bootstrap.py", line 840, in _gcd_import
        loader.load_module(name)
      File "/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Lib/importlib/_bootstrap.py", line 466, in load_module
        return self._load_module(fullname)
      File "/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Lib/importlib/_bootstrap.py", line 170, in decorated
        return fxn(self, module, *args, **kwargs)
      File "/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Lib/importlib/_bootstrap.py", line 371, in _load_module
        exec(code_object, module.__dict__)
      File "/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Lib/curses/__init__.py", line 13, in <module>
        from _curses import *
      File "/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Lib/importlib/_bootstrap.py", line 190, in inner
        return method(self, name, *args, **kwargs)
      File "/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Lib/importlib/_bootstrap.py", line 126, in wrapper
        module = fxn(*args, **kwargs)
      File "/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Lib/importlib/_bootstrap.py", line 139, in wrapper
        module = fxn(self, *args, **kwargs)
      File "/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Lib/importlib/_bootstrap.py", line 574, in load_module
        return imp.load_dynamic(fullname, self._path)
    UnicodeDecodeError: 'utf8' codec can't decode byte 0xb5 in position 0: invalid start byte

    The locale encoding is UTF-8 (LANG=en_US.UTF-8), Python directory is /var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build.

    Full header:
    ---
    make buildbottest TESTOPTS= TESTPYTHONOPTS= TESTTIMEOUT=3600
    in dir /var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build (timeout 3900 secs)
    watching logfiles {}
    argv: ['make', 'buildbottest', 'TESTOPTS=', 'TESTPYTHONOPTS=', 'TESTTIMEOUT=3600']
    environment:
    HOME=/var/lib/buildbot
    LANG=en_US.UTF-8
    LOGNAME=buildbot
    MAIL=/var/mail/buildbot
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
    PWD=/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build
    SHELL=/bin/sh
    SPEECHD_PORT=6678
    TERM=linux
    USER=buildbot
    XDG_SESSION_COOKIE=559ce1e92f80d0de13b3936e4c1475f9-29.919136-1746652091
    closing stdin
    using PTY: False
    ---

    In Unicode, U+00B5 is µ (micro sign).

    Add Barry, the owner of the buildbot, to the nosy list. Add Brett to the nosy, even if I don't think that the problem comes from the importlib.

    @vstinner vstinner added stdlib Python modules in the Lib dir topic-unicode labels Dec 10, 2011
    @vstinner
    Copy link
    Member Author

    The compilation of the module failed for the same reason:

    building '_curses' extension
    gcc -pthread -fPIC -Wno-unused-result -g -O0 -Wall -Wstrict-prototypes -DHAVE_NCURSESW=1 -I/usr/include/ncursesw -IInclude -I. -I./Include -I/usr/include/arm-linux-gnueabi -I/usr/local/include -I/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build -c /var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Modules/_cursesmodule.c -o build/temp.linux-armv7l-3.3-pydebug/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Modules/_cursesmodule.o
    gcc -pthread -shared build/temp.linux-armv7l-3.3-pydebug/var/lib/buildbot/buildarea/3.x.warsaw-ubuntu-arm/build/Modules/_cursesmodule.o -L/usr/lib/arm-linux-gnueabi -L/usr/local/lib -lncursesw -o build/lib.linux-armv7l-3.3-pydebug/_curses.cpython-33dm.so
    *** WARNING: importing extension "_curses" failed with <class 'UnicodeDecodeError'>: 'utf8' codec can't decode byte 0xb5 in position 0: invalid start byte

    @vstinner
    Copy link
    Member Author

    The problem comes maybe from the name of a curses key, keyname(). PyInit__curses() gets the name of all keys (KEY_MIN..KEY_MAX).

    @warsaw
    Copy link
    Member

    warsaw commented Dec 11, 2011

    Fails in exactly the same way when built from my shell account using current hg head. Does not fail on same version of OS on amd64.

    @vstinner
    Copy link
    Member Author

    @barry: can you try to get a trace using gdb? Start python in gdb, set a breapoint on PyErr_SetObject, continue, run the Python command "import _curses", get the gdb traceback (or continue if the error is not the UTF-8 error).

    @brettcannon
    Copy link
    Member

    This fails for me on OS X Snow Leopard using LLVM 3.0.

    And I agree with your initial guess, Victor: I don't see how importlib could possibly be the issue here since it's using load_dynamic() and not loading some Python source itself.

    @vstinner
    Copy link
    Member Author

    vstinner commented Oct 1, 2012

    What is the status of this issue? Is anyone able to reproduce it? If not, I would like to close it.

    @brettcannon
    Copy link
    Member

    I can't, so setting to pending so that if no one speaks up the issue will close.

    @serhiy-storchaka
    Copy link
    Member

    Barry, you can reproduce it? The issue obviously in PyUnicode_FromString() call from PyCursesWindow_GetKey(). We can try latin1 encoding, locale encoding or utf-8 with surrogateescape error handler.

    @serhiy-storchaka
    Copy link
    Member

    Here are three patches. I think one of them (or any) should fix the issue. The
    question is what solution returns more suitable result for non-ascii key
    names.

    @warsaw
    Copy link
    Member

    warsaw commented Oct 16, 2012

    I cannot reproduce it with Python 3.3 hg head on my ARM buildbot. _curses builds and imports just fine now.

    @brettcannon
    Copy link
    Member

    Should we just close this, Barry?

    @vstinner
    Copy link
    Member Author

    The issue obviously in PyUnicode_FromString() call from PyCursesWindow_GetKey().
    We can try latin1 encoding, locale encoding or utf-8 with surrogateescape error handler.

    PyUnicode_FromString() uses the UTF-8 decoder. I don't think that curses uses any non-ASCII name for a key. If we get a name which is not decodable from UTF-8, I bet that we have a more serious issue than the encoding. I prefer not to change the encoding for getkey (UTF-8 is just fine).

    It looks like nobody saw this issue since months, even after the final release of Python 3.3. I'm closing this issue. It doesn't contain any useful information, it would be easy to reopen it or open a new issue.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir topic-unicode
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants