Character set woes with binary data

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Apr 1 11:09:24 CEST 2007


En Sun, 01 Apr 2007 05:21:25 -0300, Michael B. Trausch <fd0man at gmail.com>  
escribió:

> I am attempting to piece together a Python client for Fotobilder, the
> picture management server on Livejournal.
>
> The protocol calls for binary data to be transmitted, and I cannot seem
> to be able to do it, because I get this error:
>
>>>> sb.UploadSinglePicture('/home/mbt/IMG_2618.JPG')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "scrapbook.py", line 181, in UploadSinglePicture
>     {Request['UploadPic.Meta.Filename']: pic_mem})
>   File "scrapbook.py", line 237, in ComposeMIME
>     return(self.EncodeMIME(fields, files))
>   File "scrapbook.py", line 226, in EncodeMIME
>     body = eol.join(L)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0:
> ordinal not in range(128)
>>>>

What's scrapbook.py? Where do you find it?

> When putting the MIME segments (listed line-by-line in a Python list)
> together to transmit them.  The files are typically JPG or some other
> binary format, and as best as I understand the protocol, the binary data
> needs to be transmitted directly (this is evidenced by looking at the
> tcp-stream of an existing client for uploading files).

But I think your problem has nothing to do with MIME: you are mixing  
unicode and string objects; from your traceback, either the "L" list or  
"eol" contain unicode objects that can't be represented as ASCII strings.

> It seems that Python thinks it knows better than I do, though.  I want
> to send this binary data straightaway to the server.  :-)

You don't appear to be using the standard email package (which includes  
MIME support) so don't blame Python...

-- 
Gabriel Genellina




More information about the Python-list mailing list