Python cgi script - outputting images

Gerhard Häring gerhard.nospam at
Sun Jul 1 13:07:01 EDT 2001

On Sun, 01 Jul 2001 15:37:35 GMT, Mexican Bandit <eli-wallach at> wrote:
>Wondering of anyone can help - Python newbie. I'm trying to write a
>Python cgi script which outputs a gif or jpg image from another
>import urllib
>print "Content-Type: image/jpeg"
>image = urllib.urlopen("")
>The output of the image is corrupted. I suspect this is to do with
>'print' turning everything into strings?
>How do I output raw image data?

Your code works fine on my machine. "print" should not be the problem, it has
always worked fine with binary data for me. So it seems your problem is not
Python, but either the browser or the webserver.

mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:              public key at homepage
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))

More information about the Python-list mailing list