CGI and logging module

Peter Otten __peter__ at web.de
Thu Nov 18 16:37:42 EST 2004


Peter Hansen wrote:

> 2. If you want to see what is going wrong, put a try/except
> around the import statement and try to write something useful
> along with your results:
> 
> err = ''
> try:
>     import logging
> except Exception, ex:
>     err = str(ex)
> 
> print 'Content-type: test/html\r\n\r\n'
> blah blah blah
> print '<p>Error: %s</p>\r\n'
> 
> If you can manage to import the sys and traceback modules,
> you can get a more fully formatted exception using
> ''.join(traceback.format_exception(*sys.exc_info()))

I've just discovered the cgitb module, which offers a minimally intrusive
way to debug cgi scripts - just add

import cgitb
cgitb.enable()

at the top of the script.

(Yet another)
Peter




More information about the Python-list mailing list