473,804 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.UploadSing lePicture('/home/mbt/IMG_2618.JPG')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "scrapbook. py", line 181, in UploadSinglePic ture
{Request['UploadPic.Meta .Filename']: pic_mem})
File "scrapbook. py", line 237, in ComposeMIME
return(self.Enc odeMIME(fields, files))
File "scrapbook. py", line 226, in EncodeMIME
body = eol.join(L)
UnicodeDecodeEr ror: '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.co m
Phone: (404) 592-5746
Jabber IM:
fd****@gmail.co m
fd****@livejour nal.com
Demand Freedom! Use open and free protocols, standards, and software!

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

iD8DBQBGD2uF0kE/IBnFmjARAn4BAJ4 658n45aZmSUUlwt 8tXrW1CuYg1ACcD 2l6
xurwY+hB406KiEJ 9RFQnA8k=
=gfl/
-----END PGP SIGNATURE-----

Apr 1 '07 #1
0 1074

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

Similar topics

2
2709
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 from a binary file ). My code fragment looks as follows: void MyStream ::readStream(char * buffer, size_t length) { is.get( buffer, length + 1); //read length bytes from the stream
1
3475
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 value representing the width of the bmp image. So far, I have been able to use fstream's seek, write, and read to pull out chucks of bytes and convert them to usable integers straight out of the binary file. It works well, but over the course of...
18
4637
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 has some different characters in it that I am trying to remove. The small a with two dots over it and the small y with two dots over it. Here is my code so far to remove the small y: Private Sub Button2_Click(ByVal sender As System.Object, ByVal...
17
2146
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 below. #include <stdio.h> main() { long nc;
0
10600
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10097
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6867
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.