āžœ

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 Segev Finer
Recipients Segev Finer, paul.moore, steve.dower, tim.golden, zach.ware
Date 2018-07-30.17:49:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1532972971.81.0.56676864532.issue34283@psf.upfronthosting.co.za>
In-reply-to
Content
Found by trying to use pip: https://github.com/pypa/pip/issues/5665.

This is likely affected by the console code page.

Python version: 2.7.15 64 bit
OS: Windows 10.0.17134.165 x64
The console locale is set to cp872.
The console font is consolas.

Apparently, msvcrt does charset conversion when writing to its file descriptors based on the set locale! and it's even special cased to handle the OEM console code page (You can see this in crt/src/write.c:_write_nolock if you have MSVC 2008).

When the "C" locale is set, no conversion is done. Python encodes to the OEM code page, and it passes through to the console unscathed. But once you do setlocale than the CRT expects you to use the ANSI code page, but Python will be encoding to the OEM code page which will result in this error from fwrite.

file.encoding in Python 2 is also not settable directly from Python (C API only), it's only used for stdio and set internally on startup: Python/pythonrun.c:349-378.

I found this describing this: Why printf can display non-ASCII characters when ā€œCā€ locale is used?.

    #!/usr/bin/env python2
    from __future__ import print_function
    import locale

    print(u' |\u2588')  # Works
    locale.setlocale(locale.LC_ALL, '')
    print(u' |\u2588')  # IOError: [Errno 42] Illegal byte sequence
History
Date User Action Args
2018-07-30 17:49:31Segev Finersetrecipients: + Segev Finer, paul.moore, tim.golden, zach.ware, steve.dower
2018-07-30 17:49:31Segev Finersetmessageid: <1532972971.81.0.56676864532.issue34283@psf.upfronthosting.co.za>
2018-07-30 17:49:31Segev Finerlinkissue34283 messages
2018-07-30 17:49:31Segev Finercreate