Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Sending binary data over CGI
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Walter Huf" data-source="post: 1753339"><p>Okay, I'm busy making a wonderful cgi program, and everything is working </p><p>wonderfully so far. I'm using the standard cgi library and the Cookie </p><p>library and they have been a huge help. Thanks to those who have created </p><p>them!</p><p>However, if I try to send binary data, like jpgs, through cgi, the data </p><p>gets corrupted in a very small manner. Whenever my program sends the </p><p>character 10, it gets converted to character 13+character 10. I found out </p><p>this only happens when I send data to stdout. If I send the data to a </p><p>standard file object, it works fine. However, with the stdout, the problem </p><p>arises.</p><p>Here is the relevant part of the code:</p><p>---Begin</p><p>from sys import stdout</p><p>def senddownloaddata(file): #file is a pointer to an open file</p><p> line=file.read(1) #file pointer opening and closing are</p><p> while len(line)==1: # handled outside of function</p><p> stdout.write(line)</p><p> line=file.read(1)</p><p> stdout.write(line)</p><p>---End</p><p>Now the code that copies files:</p><p>---Begin</p><p>curdir="C:\windows\desktop"</p><p>temp=file(curdir+"/bach.it","rb",0)</p><p>out=file(curdir+"/bach2.it","wb",0)</p><p>data=temp.read(1)</p><p>while len(data)==1:</p><p> out.write(data)</p><p> data=temp.read(1)</p><p>temp.close()</p><p>out.close()</p><p>---End</p><p></p><p>I'm using Windows 98 SE with an Apache 2.0.44 Win32 server. That all works </p><p>fine. The first line of the interactive script says:</p><p>PythonWin 2.3.2 (#49, Nov 13 2003, 10:34:54) [MSC v.1200 32 bit (Intel)] on </p><p>win32.</p><p>I'm assuming that means I have Python 2.3.2. Everything else in the program </p><p>works very nice, except for the data corruption.</p><p></p><p>Please help me with this problem. It has me stumped.</p><p>Thanks in advance!</p><p></p><p>--Walter Huf--</p><p><a href="mailto:hufman@cobalty.com">hufman@cobalty.com</a></p></blockquote><p></p>
[QUOTE="Walter Huf, post: 1753339"] 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 them! 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 arises. Here is the relevant part of the code: ---Begin from sys import stdout def senddownloaddata(file): #file is a pointer to an open file line=file.read(1) #file pointer opening and closing are while len(line)==1: # handled outside of function stdout.write(line) line=file.read(1) stdout.write(line) ---End Now the code that copies files: ---Begin curdir="C:\windows\desktop" temp=file(curdir+"/bach.it","rb",0) out=file(curdir+"/bach2.it","wb",0) data=temp.read(1) while len(data)==1: out.write(data) data=temp.read(1) temp.close() out.close() ---End 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 win32. 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-- [email]hufman@cobalty.com[/email] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Sending binary data over CGI
Top