You are piping data into Python; at that point Python's stdin
is no longer attached to a TTY (your console) and won't guess at what the encoding might be. Instead, the default system locale is used; on your system that's cp1251 (the Windows Latin-1-based codepage).
Set the PYTHONIOENCODING
environment variable to override:
PYTHONIOENCODING
If this is set before running the interpreter, it overrides the encoding used for stdin/stdout/stderr, in the syntax encodingname:errorhandler
. Both the encodingname
and the :errorhandler
parts are optional and have the same meaning as in str.encode()
.
PowerShell doesn't appear to support per-command-line environment variables the way UNIX shells do; the easiest is to just set the variable first:
Set-Item Env:PYTHONIOENCODING "UTF-8"
or even
Set-Item Env:PYTHONIOENCODING "cp65001"
as the Windows UTF-8 codepage is apparently not quite UTF-8 really, depending on the Windows version and on wether or not pipe redirection is used.