UnicodeDecodeError

Fredrik Lundh fredrik at pythonware.com
Thu May 5 16:11:15 EDT 2005


"thomas ct" wrote:

> what i was trying to say was how the various tuples behave..if i use
>
> file = ('file', filename, data)  #it gives me unicode error
> in this case I am using binary data..
>
> file = ('file', filename, 'data'*100)
> but the same filename works fine if i pass text data
>
> file = ('file', 'test.pdf', data)
>
> so if hardcode the file name /use
> filename=filename.encode("ascii") things work with binary data as well..
>
> I was wondering why..

if you mix a Unicode string with an 80-bit string, Python will try to
convert the 8-bit string to a Unicode string, which doesn't work if
the string contains characters outside the ASCII set.

you have to either encode the Unicode string into an 8-bit string, or
decode the non-ASCII string into a Unicode string.

</F>






More information about the Python-list mailing list