CGI Debugging

Fredrik Lundh fredrik at
Fri May 26 03:54:07 EDT 2000

richard_chamberlain at wrote:
> I'm having great difficulties getting Python to work via CGI.
> Is there anyway I can get the traceback on to the web page so I know what's
> happening?

the easiest way is to split your CGI module in two parts; use the following
script as a wrapper, and place the program logic in a separate script ("my-
script.main()" in this case):

#!/usr/bin/env python

import cgi, StringIO, sys, traceback

    import myscript
    print "Content-Type:", "text/html"
    file = StringIO.StringIO()
    print "<pre>"
    print cgi.escape(file.getvalue())
    print "</pre>"

> I haven't got access to error logs so I can't look at it that way.


More information about the Python-list mailing list