Python cgi script - outputting images

Gerhard Häring gerhard.nospam at bigfoot.de
Sun Jul 1 19:07:01 CEST 2001


On Sun, 01 Jul 2001 15:37:35 GMT, Mexican Bandit <eli-wallach at ugly.com> wrote:
>Hi,
>
>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
>server...
>
>----
>import urllib
>
>print "Content-Type: image/jpeg"
>print
>
>image = urllib.urlopen("http://127.0.0.1/splogo.jpg")
>print image.read()
>----
>
>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.

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://highqualdev.com              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