[mod_python] cgi handler bug?

Gregory Bond gnb at itga.com.au
Mon Dec 23 11:24:46 EST 2002

I wrote: 

> But the HTML
> generated by the CGI is sent twice, so my page displays double. 

Found it.

In mod_python.apache.py, in the CGIStdout::write() routine, the
self.headers_sent variable is never being set, so the first chunk of stuff from
the CGI program (in my case, all but the last newline) is being handled and
sent twice.

The following patch fixes both CGIhandler problems, and my CGIs now happily 
operate under mod_python:

diff -u ~gnb/mod_python-3.0.1/lib/python/mod_python/apache.py /usr/local/lib/python2.2/site-packages/mod_python/apache.py
--- /home/users/gnb/mod_python-3.0.1/lib/python/mod_python/apache.py    Fri Nov  8 11:15:11 2002
+++ /usr/local/lib/python2.2/site-packages/mod_python/apache.py Mon Dec 23 11:18:56 2002
@@ -723,6 +723,7 @@
                         self.req.headers_out.add(h, v)
+               self.headers_sent = 1
                 # write the body if any at this point
@@ -761,7 +762,7 @@
     osenv = os.environ
     # restore env
-    for k in osenv:
+    for k in osenv.keys():
         del osenv[k]
     for k in sav_env:
         osenv[k] = env[k]

More information about the Mod_python mailing list