Strange UnicodeEncodeError in Windows image on Azure DevOps and Github

Jessica Smith 12jessicasmith34 at gmail.com
Sun Nov 13 14:35:07 EST 2022


On Fri, Nov 11, 2022 at 8:16 PM Eryk Sun <eryksun at gmail.com> wrote:
> If sys.std* are console files, then in Python 3.6+, sys.std*.buffer.raw will be _io._WindowsConsoleIO
> io.TextIOWrapper uses locale.getpreferredencoding(False) as the default encoding

Thank you for your replies - checking the sys.stdout.buffer.raw value
is what finally helped me understand. Turns out, the Windows agent is
redirecting the output of all python commands to a file, so sys.stdout
is a file using the locale encoding of cp1252, instead of being a
stream using encoding utf8. I wrote up a gist with my findings to
hopefully help out some other poor soul in the future:
https://gist.github.com/NodeJSmith/e7e37f2d3f162456869f015f842bcf15


More information about the Python-list mailing list