The cgitb module provides a special exception handler for CGI scripts. After this module is activated, if an uncaught exception occurs, a detailed, formatted report will be sent to the Web browser. The report includes a traceback showing excerpts of the source code for each level, as well as the values of the arguments and local variables to currently running functions, to help you debug the problem. Optionally, you can save this information to a file instead of sending it to the browser.
To enable this feature, simply add one line to the top of your CGI script:
import cgitb; cgitb.enable()
The options to the enable() function control whether the report is displayed in the browser and whether the report is logged to a file for later analysis.
sys.excepthook
.
The optional argument display defaults to 1
and can be set
to 0
to suppress sending the traceback to the browser.
If the argument logdir is present, the traceback reports are
written to files. The value of logdir should be a directory
where these files will be placed.
The optional argument context is the number of lines of
context to display around the current line of source code in the
traceback; this defaults to 5
.
sys.exc_info()
. If the info argument
is not supplied, the current exception is obtained from
sys.exc_info()
.