This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author zkonge
Recipients zkonge
Date 2020-08-06.19:52:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1596743565.22.0.770154691166.issue41497@roundup.psfhosted.org>
In-reply-to
Content
A potential UnicodeDecodeError could be raised when run "python -m dis" on non-utf8 encoding environment.

Assume there is a file named "a.py", and contains "print('喵')", then save with UTF8 encoding.

Run "python -m dis ./a.py", on non-UTF8 encoding environment, for example a Windows PC which default language is Chinese.

A UnicodeDecodeError raised.

Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python38\lib\dis.py", line 553, in <module>
    _test()
  File "C:\Program Files\Python38\lib\dis.py", line 548, in _test
    source = infile.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xb5 in position 9: illegal multibyte sequence

That because Windows' default encoding is decided by language. Chinese use cp936(GB2312) as default encoding and can't handle UTF8 encoding.

It just need to read in "rb" mode instead of "r".
History
Date User Action Args
2020-08-06 19:52:45zkongesetrecipients: + zkonge
2020-08-06 19:52:45zkongesetmessageid: <1596743565.22.0.770154691166.issue41497@roundup.psfhosted.org>
2020-08-06 19:52:45zkongelinkissue41497 messages
2020-08-06 19:52:44zkongecreate