How do I return binary data from a python CGI called from CGIHTTPServer?
Dirck Blaskey
dirck at pacbell.net
Wed Jun 6 14:43:08 EDT 2001
"Alex Martelli" <aleaxit at yahoo.com> wrote in message news:<9f96kb01mq8 at enews1.newsguy.com>...
> "Mark Wright" <mwright at pro-ns.net> wrote in message
> news:f9ff3f62.0106011427.6243e5e9 at posting.google.com...
> ...
> > But my original problem/question remains: how does a CGI program
> > return binary data on windows? Is it even possible? The problem is
>
> python.exe must be run with option -u, to have binary standard input
> and output streams, rather than text ones as it has by default.
In order to send or receive binary files from Python CGIs under IIS
(and Xitami) under Win32, I had to do the following in the scripts,
instead of using the -u option:
try:
import msvcrt
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
msvcrt.setmode(sys.stdout.fileno(),os.O_BINARY)
except:
pass
The -u option broke something in cgi.py, I don't remember what.
d
More information about the Python-list
mailing list