dave at rotwang.freeserve.co.uk
Tue Feb 1 17:06:41 CET 2000
I'm trying to write a CGI script that returns image data instead of HTML.
The problem is that sys.stdout is opened in text mode, and I need to write
in binary. As a result each embedded "\n" in the image data gets expanded
into "\r\n", corrupting the image. I have tried the following:
out = os.fdopen(sys.stdout.fileno(), "wb")
But the "wb" mode does not seem to override the underlying mode of stdout.
I'm using Python 1.5.2 on Win 98 SE, talking to Apache 1.3.9.
How can I write to stdout in binary mode?
More information about the Python-list