473,414 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Character set woes with binary data

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)
>>
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).

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

This is a hex dump of what one file looks like being uploaded to the
server (partial; the file is 3.8 MB):

000001CB ff d8 ff e1 3b fc 45 78 69 66 00 00 49 49 2a 00 ....;.Ex
if..II*.
000001DB 08 00 00 00 09 00 0f 01 02 00 10 00 00 00 7a
00 ........ ......z.
000001EB 00 00 10 01 02 00 10 00 00 00 aa 00 00 00 12
01 ........ ........
000001FB 03 00 01 00 00 00 01 00 00 00 1a 01 05 00 01
00 ........ ........
0000020B 00 00 da 00 00 00 1b 01 05 00 01 00 00 00 e2
00 ........ ........
0000021B 00 00 28 01 03 00 01 00 00 00 02 00 00 00 31
01 ..(..... ......1.
0000022B 02 00 1e 00 00 00 ea 00 00 00 13 02 03 00 01
00 ........ ........
0000023B 00 00 02 00 00 00 69 87 04 00 01 00 00 00 54
01 ......i. ......T.
0000024B 00 00 ac 12 00 00 48 65 77 6c 65 74 74 2d 50 61 ......He
wlett-Pa
0000025B 63 6b 61 72 64 00 00 00 00 00 00 00 00 00 00 00
ckard... ........
0000026B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 ........ ........
0000027B 00 00 00 00 00 00 50 68 6f 74 6f 73 6d 61 72 74 ......Ph
otosmart
0000028B 20 4d 35 32 35 00 00 00 00 00 00 00 00 00 00 00
M525... ........
0000029B 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 ........ ........
000002AB 00 00 00 00 00 00 e6 00 00 00 01 00 00 00 e6
00 ........ ........
000002BB 00 00 01 00 00 00 56 65 72 73 69 6f 6e 20 31 2e ......Ve
rsion 1.
000002CB 34 31 30 30 2c 53 4e 3a 43 4e 36 34 31 44 33 31 4100,SN:
CN641D31
000002DB 4a 35 53 00 00 00 00 00 00 00 00 00 00 00 00 00
J5S..... ........
000002EB 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff
ff ........ ........
000002FB ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ........ ........
0000030B ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ........ ........
0000031B ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ........ ........
0000032B 27 00 9a 82 05 00 01 00 00 00 96 08 00 00 9d 82
'....... ........

Is there any way to tell Python to ignore the situation and treat the
entire thing as simply a stream of bytes? I cannot seem to find one,
though I have found a great many posts on this mailing list regarding
issues in the past. It doesn't look like translating the file to base64
is an option for me.

— Mike

--
Michael B. Trausch
fd****@gmail.com
Phone: (404) 592-5746
Jabber IM:
fd****@gmail.com
fd****@livejournal.com
Demand Freedom! Use open and free protocols, standards, and software!

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBGD2uF0kE/IBnFmjARAn4BAJ4658n45aZmSUUlwt8tXrW1CuYg1ACcD2l6
xurwY+hB406KiEJ9RFQnA8k=
=gfl/
-----END PGP SIGNATURE-----

Apr 1 '07 #1
0 1051

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rakesh Sinha | last post by:
Hi, I am writing this application in C++. It reads data from binary files. My current requirement is that: Given a positive number N, I have to read in N bytes from the input stream (which is...
1
by: rusttree | last post by:
I'm working on a program that manipulates bmp files. I know the offset location of each piece of relevent data within the bmp file. For example, I know the 18th through 21st byte is an integer...
18
by: james | last post by:
Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits the "," and then copies the results into a listbox. The data also...
17
by: Gladiator | last post by:
When I am trying to execute a program from "The C Programming Language" by Dennis Ritchie, I tried to run the following program.I am using Dev++ as a compiler software. The Program is presented...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.