Sending binary data over CGI

Walter Huf hufman at
Thu Mar 4 04:04:27 CET 2004

Okay, I'm busy making a wonderful cgi program, and everything is working 
wonderfully so far. I'm using the standard cgi library and the Cookie 
library and they have been a huge help. Thanks to those who have created 
However, if I try to send binary data, like jpgs, through cgi, the data 
gets corrupted in a very small manner. Whenever my program sends the 
character 10, it gets converted to character 13+character 10. I found out 
this only happens when I send data to stdout. If I send the data to a 
standard file object, it works fine. However, with the stdout, the problem 
Here is the relevant part of the code:
from sys import stdout
def senddownloaddata(file):    	#file is a pointer to an open file    	    	#file pointer opening and closing are
    while len(line)==1:    	    	# handled outside of function
Now the code that copies files:
while len(data)==1:

I'm using Windows 98 SE with an Apache 2.0.44 Win32 server. That all works 
fine. The first line of the interactive script says:
PythonWin 2.3.2 (#49, Nov 13 2003, 10:34:54) [MSC v.1200 32 bit (Intel)] on 
I'm assuming that means I have Python 2.3.2. Everything else in the program 
works very nice, except for the data corruption.

Please help me with this problem. It has me stumped.
Thanks in advance!

--Walter Huf--
hufman at

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- - The #1 Newsgroup Service in the World!
-----==  Over 100,000 Newsgroups - 19 Different Servers! =-----

More information about the Python-list mailing list