ahopkins at ahopkins.dynacare.com
Tue Feb 1 12:47:44 EST 2000
On Tue, 1 Feb 2000 16:06:41 -0000, Dave Berkeley <dave at rotwang.freeserve.co.uk> wrote:
>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")
Are you sure? I've successfully done this on
Apache and IIS with the following code fragment:
I'm not sure why you are [re]opening sys.stdout but it should be open
when your CGI is called.
>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?
Sr. Systems Specialist
ahopkins at dynacare.com
More information about the Python-list