Name
enable
Synopsis
enable(display
=True,logdir
=None,context
=5)
Installs an exception hook, via sys.excepthook
, to
diagnose propagated exceptions. The hook displays the exception
traceback on the browser if display
is
true. The hook logs the exception traceback to a file in directory
logdir
if
logdir
is not None
. In
the traceback, the hook shows context
lines of source code per frame.
In practice, you can start all of your CGI scripts with:
import cgitb cgitb.enable( )
and be assured of good error reporting to the browser with minimal
effort on your part. Of course, when you don’t want
users of your page to see Python tracebacks from your scripts on
their browsers, you can call
cgitb(False,'/my/log/dir')
and get the error
reports, with exception tracebacks, as files in directory
/my/log/dir
instead.
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.