How do I return binary data from a python CGI called from CGIHTTPServer?

Mark Wright mwright at pro-ns.net
Fri Jun 1 18:27:38 EDT 2001


Skip Montanaro <skip at pobox.com> wrote in message news:<mailman.991419724.7209.python-list at python.org>...
> Mark>     out_file.write('Content-type=application/octet-stream\n\n')
> 
> Should be
> 
>     Content-type: application/octet-stream
> 
> (colon, then space instead of equals).

Well, that explains why nothing was working under Mozilla
('Content-type=' works under IE - go figure), good thing I didn't
finish that bug report I was working on.

And a bunch of debuging code 'print's that occurred before the
'Content-type' line explain why garbage appeared on IE's screen.

But my original problem/question remains: how does a CGI program
return binary data on windows?  Is it even possible?  The problem is
that this chunk of code in a CGI-program doesn't seem to work under
Windows:

   data = open('mybinaryfile.dat', 'rb').read()
   print data

presumably because of \r\n issues.  Is there a way to convince
CGIHTTPServer to read data as binary and not perform CRLF conversion?

Mark



More information about the Python-list mailing list