CGI Debugging

Fredrik Lundh fredrik at pythonware.com
Fri May 26 09:54:07 CEST 2000


richard_chamberlain at ntlworld.com 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

try:
    import myscript
    myscript.main()
except:
    print "Content-Type:", "text/html"
    print
    file = StringIO.StringIO()
    traceback.print_exc(file=file)
    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.

</F>





More information about the Python-list mailing list