CGI python 3 write RAW BINARY

Dodo dodo_do_not_wake_up at yahoo.Fr
Fri May 7 10:33:13 EDT 2010


Le 01/05/2010 12:52, Dodo a écrit :
> Le 30/04/2010 17:52, Antoine Pitrou a écrit :
>> Le Thu, 29 Apr 2010 23:37:32 +0200, Dodo a écrit :
>>> ....I don't get a thing.
>>> Now with the fix :
>>> All browsers shows a different thing, but not the image!
>>> http://ddclermont.homeip.net/misc/python/
>>>
>>> If I save it to computer :
>>> * Windows image viewer won't read it
>>> * Irfanview can read it without problems
>>
>> Did you set the content-type and content-length in the HTTP headers?
>> Can you post your code?
>>
>>


> I didn't know about content-lenght
> Here's the new code (I used a fixed image patch to make sure this is not
> the source of the problem)
>
>
> #!/usr/bin/python3
> import cgi, sys, cgitb
> cgitb.enable()
>
> f = open("/home/dodo/54.jpg", "rb")
> data = f.read()
> l = len(data)
> f.close()
>
> print("Content-type:image/jpg\nContent-length:%d\n\n" % l)
>
> sys.stdout.flush()
> sys.stdout.buffer.write( data )
>
>
>
> Dorian
Anyone?



More information about the Python-list mailing list