2001-12-04 18:47:42 -04:00
|
|
|
\section{\module{cgitb} ---
|
|
|
|
Traceback manager for CGI scripts}
|
|
|
|
|
|
|
|
\declaremodule{standard}{cgitb}
|
|
|
|
\modulesynopsis{Configurable traceback handler for CGI scripts.}
|
2001-12-18 11:51:55 -04:00
|
|
|
\moduleauthor{Ka-Ping Yee}{ping@lfw.org}
|
2001-12-04 18:47:42 -04:00
|
|
|
\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
|
|
|
|
|
2001-12-18 11:51:55 -04:00
|
|
|
\versionadded{2.2}
|
|
|
|
\index{CGI!exceptions}
|
2001-12-04 18:47:42 -04:00
|
|
|
\index{CGI!tracebacks}
|
2001-12-20 13:13:09 -04:00
|
|
|
\index{exceptions!in CGI scripts}
|
|
|
|
\index{tracebacks!in CGI scripts}
|
2001-12-04 18:47:42 -04:00
|
|
|
|
2003-06-17 09:58:31 -03:00
|
|
|
The \module{cgitb} module provides a special exception handler for Python
|
2004-08-26 07:40:12 -03:00
|
|
|
scripts. (Its name is a bit misleading. It was originally designed to
|
2003-06-17 09:58:31 -03:00
|
|
|
display extensive traceback information in HTML for CGI scripts. It was
|
|
|
|
later generalized to also display this information in plain text.) After
|
|
|
|
this module is activated, if an uncaught exception occurs, a detailed,
|
|
|
|
formatted report will be displayed. The report
|
2001-12-20 13:13:09 -04:00
|
|
|
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
|
2001-12-18 11:51:55 -04:00
|
|
|
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:
|
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
import cgitb; cgitb.enable()
|
|
|
|
\end{verbatim}
|
|
|
|
|
|
|
|
The options to the \function{enable()} function control whether the
|
|
|
|
report is displayed in the browser and whether the report is logged
|
|
|
|
to a file for later analysis.
|
2001-12-04 18:47:42 -04:00
|
|
|
|
|
|
|
|
|
|
|
\begin{funcdesc}{enable}{\optional{display\optional{, logdir\optional{,
|
2003-06-17 09:58:31 -03:00
|
|
|
context\optional{, format}}}}}
|
2001-12-04 18:47:42 -04:00
|
|
|
This function causes the \module{cgitb} module to take over the
|
2001-12-18 11:51:55 -04:00
|
|
|
interpreter's default handling for exceptions by setting the
|
2007-04-01 18:29:15 -03:00
|
|
|
value of \member{\refmodule{sys}.excepthook}.
|
2001-12-18 11:51:55 -04:00
|
|
|
\withsubitem{(in module sys)}{\ttindex{excepthook()}}
|
2001-12-04 18:47:42 -04:00
|
|
|
|
2001-12-18 11:51:55 -04:00
|
|
|
The optional argument \var{display} defaults to \code{1} and can be set
|
|
|
|
to \code{0} to suppress sending the traceback to the browser.
|
|
|
|
If the argument \var{logdir} is present, the traceback reports are
|
|
|
|
written to files. The value of \var{logdir} should be a directory
|
|
|
|
where these files will be placed.
|
|
|
|
The optional argument \var{context} is the number of lines of
|
|
|
|
context to display around the current line of source code in the
|
|
|
|
traceback; this defaults to \code{5}.
|
2003-06-17 09:58:31 -03:00
|
|
|
If the optional argument \var{format} is \code{"html"}, the output is
|
|
|
|
formatted as HTML. Any other value forces plain text output. The default
|
|
|
|
value is \code{"html"}.
|
2001-12-04 18:47:42 -04:00
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{handler}{\optional{info}}
|
2001-12-18 11:51:55 -04:00
|
|
|
This function handles an exception using the default settings
|
|
|
|
(that is, show a report in the browser, but don't log to a file).
|
|
|
|
This can be used when you've caught an exception and want to
|
|
|
|
report it using \module{cgitb}. The optional \var{info} argument
|
|
|
|
should be a 3-tuple containing an exception type, exception
|
|
|
|
value, and traceback object, exactly like the tuple returned by
|
2007-04-01 18:29:15 -03:00
|
|
|
\function{\refmodule{sys}.exc_info()}. If the \var{info} argument
|
2001-12-18 11:51:55 -04:00
|
|
|
is not supplied, the current exception is obtained from
|
2007-04-01 18:29:15 -03:00
|
|
|
\function{\refmodule{sys}.exc_info()}.
|
2001-12-04 18:47:42 -04:00
|
|
|
\end{funcdesc}
|