[Tutor] UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in position

Peter Otten __peter__ at web.de
Sun Mar 11 11:37:04 CET 2012


Steven D'Aprano wrote:

> glyph. He shouldn't get a UnicodeDecodeError when printing. I smell a
> bug since print shouldn't be decoding anything. (At worst, it needs to
> *encode*.)

You have correctly derived the actual traceback ;)

[Robert]
> It starts to print until it hits the wonderful character é or '\xe9',
> where it gives me this happy traceback:
> Traceback (most recent call last):
>   File "C:\Users\Azaz\Desktop\CK2 Map Painter\Parser\test parser.py",
> line 8, in <module>
>     print(line)
> UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in
> position 13: illegal multibyte sequence
 
In nuce:

$ PYTHONIOENCODING=cp932 python3 -c 'print("\xe9")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in position 
0: illegal multibyte sequence

(I have to lie about the encoding; my terminal speaks UTF-8)



More information about the Tutor mailing list