UTF-8 problem encoding and decoding in Python3

Almar Klein almar.klein at gmail.com
Sun Oct 10 22:28:48 CEST 2010


please tell us what you are trying to do. Encoding (with UTF-8) is a method
to convert a Unicode string to a sequence of bytes. Decoding does the

When i open
> directly and try to decode the file the error is this: `UnicodeDecodeError:
> 'utf8' codec can't decode byte 0xff in position 0: unexpected code byte`

This means the series of byte that you are trying to convert to a string is
not valid UTF-8. It can't be, because it would not contain 0xff or 0xfe

but when i try to encode the file in the server the encode change the parts
> of the file and the result is
> this:`\xc3\xbf\xc3\x98\xc3\xbf\xc3\xa0\x00\x10JFIF` without say that the

So here you *encode* the file, not decoding it.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101010/f139d6b8/attachment.html>

More information about the Python-list mailing list