CGI -- generating images -- \x0A always added!

Bengt Richter bokr at oz.net
Wed Sep 10 00:32:38 EDT 2003


On Wed, 10 Sep 2003 03:05:51 GMT, "M-a-S" <NO-MAIL at hotmail.com> wrote:

>Hi All,
>
>I'm trying to use Python for generating (or copying) images.
>The environment is Python 2.3/Apache 2.0.43/Windows XP.
>I couldn't make Apache use mod_python (anybody can help?
>Apache complains "The requested operation has failed"
>if I add LoadModule python_module modules/mod_python.so)
>so I use the CGI mechanism. This is the sample:
>
I would try switching to using sys.stdout.write

>#!C:\Apps\Python\python.exe -u
>
 import sys
>img = open( 'a.gif', 'rb' ) # OK, don't make the image, just use the file
>if img:
>  data = img.read()
>  img.close()
>
>print "Content-type: image/gif"
>print
The above two might work ok, but might as well use
sys.stdout.write consistently instead, e.g.,

 # untested ...
 sys.stdout.write('Content-type: image/gif\n\n') # should be the same
>
>print data,
 sys.stdout.write(data)
 sys.stdout.close()
>
># EOF
>
>Everything's good, and '-u' helps not to add '\x0D' for each '\x0A'
>inside the data. BUT it seems that the last print ALWAYS adds LF
>'\x0A' in spite of the final comma. How can I fix that? Thank you.
>
HTH. It should be easy to try. Let us know.

Regards,
Bengt Richter




More information about the Python-list mailing list