Python cgitb Introduction














































Python cgitb Introduction



introduction to cgitb library in python

This module is the traceback manager for CGI scripts. It provides a exception handler for Python scripts. Using this module if an uncaught exception occurs, a detailed and formatted report of an error is displayed will be displayed. The report displayed consist of traceback which shows excerpts of the source code for each level, also the values of the arguments and local variables of currently running functions, and thus help us in debugging the problem.

Note

The name of this module is misleading as it was earlier design for showing detailed information on errors and debugging information in web applications only. But later it was updated to display detailed information of plain-text output. Unfortunately it was not renamed which led to obscurity and the module is not used as often as it should be.

Importing library

import cgitb

Method in cgitb library

enable(display=1, logdir=None, context=5, format="html")
This method  enables the cgitb module by taking over the interpreter's default exception handling

text(info, context=5)
It handles the exception described by info and formatting its traceback as text

html(info, context=5)
It handles the exception described by info and formatting its traceback as HTML

handler(info=None)
It handles an exception using the default settings i.e. it shows a report in browser, but do not log to a file


Comments