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

Bengt Richter bokr at
Wed Sep 10 06:32:38 CEST 2003

On Wed, 10 Sep 2003 03:05:51 GMT, "M-a-S" <NO-MAIL at> 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/
>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.close()
>print "Content-type: image/gif"
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,
># 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.

Bengt Richter

More information about the Python-list mailing list