Possible Duplicate:
Python, Unicode, and the Windows console
I read some strings from file and when I try to print these utf-8 strings in windows console, I get error
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: ordinal not in range(128)
I've tried to set console-encoding to utf-8 with "chcp 65001" But than I than get this error message
LookupError: unknown encoding: cp65001
I recommend you to check similar questions on stackoverflow, there are many of them.
Anyway, you can do it this way:
For files, you need to use codecs module or to encode in proper encoding.
The print command tries to convert Unicode strings to the encoding supported by the console. Try:
>>> import sys
>>> sys.stdout.encoding
'cp852'
It shows you what encoding the console supports (what is told to Python to be supported). If the character cannot be converted to that encoding, there is no way to display it correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With