A note on debugging

Debugging CGI scripts can be difficult, because the traceback from a crashed script may be buried deep in the bowels of the Web server's logging. Listing 16-7 uses a trick to make debugging easier.

Listing 16-7: CGIDebug.py import sys import traceback sys.stderr = sys.stdout print "Content-Type: text/html\n"


# The script body goes here!


print "\n\n<PRE>" traceback.print_exc()

Pointing stderr at stdout means that the output of print_exc goes to the resulting Web page. The <PRE> tag ensures that the text is shown exactly as printed.

0 0

Post a comment