[issue9511] CharacterEncoderError when reading from sys.stdin from piped input in cmd.exe

R. David Murray report at bugs.python.org
Fri Aug 6 21:32:19 CEST 2010


R. David Murray <rdmurray at bitdance.com> added the comment:

This is because python doesn't know the encoding of stdin, and so uses ASCII (I assume that's what 'charmap' is on windows...on my unix box the error message mentions ascii, not charmap).  You can tell python to use an alternate encoding by default via the PYTHONIOENCODING environment variable:

rdmurray:py3k>export PYTHONIOENCODING='utf8'
rdmurray:py3k>echo ü | ./python pycat.py    
ü

Of course, you'll need to use the Widows way of setting environment variables.

I think some consideration is being given to making this simpler, but I couldn't find an issue number for it, so I'm adding haypo as nosy since I think he was involved in that discussion.  If my memory is right, and there's no existing issue, maybe we could adopt this one for it.

----------
nosy: +haypo, r.david.murray
type:  -> behavior

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9511>
_______________________________________


More information about the Python-bugs-list mailing list