[mod_python] cgihandler repeats the whole response for each print command

Mike Looijmans mike.looijmans at asml.com
Wed Feb 19 11:03:04 EST 2003


To allow a quick migration of thousands of CGI code lines, I intended to use
the cgihandler.py handler to run existing CGI script.

However, if I setup things that way, and use a small CGI script like this one:


print 'status: 200 OK'
print 'content-type: text/html'
print
print '<HTML><HEAD><TITLE>Hello world</TITLE></HEAD>'
print '<BODY><P>Hello Mod_Python world!</P></BODY>'
print '</HTML>'

This would yield a simple 'hello world' page, but the output that is sent to
the browser is as follows:

HTTP/1.1 200 OK
Date: Wed, 19 Feb 2003 09:58:12 GMT
Server: Apache/2.0.44 (Unix) mod_python/3.0.1 Python/2.2.2
Content-Type: text/html; charset=ISO-8859-1
Connection: close

<HTML><HEAD><TITLE>Hello world</TITLE></HEAD><HTML><HEAD><TITLE>Hello
world</TITLE></HEAD>
<HTML><HEAD><TITLE>Hello world</TITLE></HEAD>
<BODY><P>Hello Mod_Python world!</P></BODY><HTML><HEAD><TITLE>Hello
world</TITLE></HEAD>
<BODY><P>Hello Mod_Python world!</P></BODY>
<HTML><HEAD><TITLE>Hello world</TITLE></HEAD>
<BODY><P>Hello Mod_Python world!</P></BODY>
</HTML><HTML><HEAD><TITLE>Hello world</TITLE></HEAD>
<BODY><P>Hello Mod_Python world!</P></BODY>
</HTML>



It seems that (except for the headers) the "sys.stdout" from the cgihandler
sends the whole output history again on each "print" command, like this class
would:

class FaultyIO:
    def __init__(self, req)
        self.msg = ''
        self.req = req
    def write(self, s):
        self.msg += s
        req.send(self.msg)








More information about the Mod_python mailing list