UTF-8 problem encoding and decoding in Python3

Hidura hidura at gmail.com
Sun Oct 10 23:01:24 CEST 2010

I try to encode a binary file what was upload to a server and is
extract from the wsgi.input of the environ and comes as an unicode

2010/10/10, Almar Klein <almar.klein at gmail.com>:
> Hi,
> 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
> reverse.
> 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
> bytes.
> 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.
>   Almar

Enviado desde mi dispositivo móvil

Diego I. Hidalgo D.

More information about the Python-list mailing list