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

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


I'm trying to return a zip file from from a python CGI script being
called by CGIHTTPServer on Windows2000 and I'm not having much luck. 
My CGI-script creates the zip file in a temporary directory and then
returns it to the client like this:

    out_file = sys.stdout
    ...

    indata = open(filename, 'rb').read()
    out_file.write('Content-type=application/octet-stream\n\n')
    out_file.write(indata)

This just creates a mess on the browser screen - I am assuming because
of CRLF conversion issues.  Is there a way to do this?  I have the
same problem with 'application/zip'.

Mark



More information about the Python-list mailing list