terry’s Weblog

weblog for terry’s finding

cgitb make your phython CGI life easier!!!

Bug, I guess no one like it especially for programmer or developer. But all of us cannot escape from this when your program or script get larger or complicated. That’s very true, so we should face it and fix it.

When you dealing with the python prompt, it’s still easy for you to get those bug warning for your syntax error, variables not define… but how about when you coding the CGI? Some time it might need run over web server to get user input for the process. Do you have some experience just got a “blank white” page for your CGI output? What the hell? What stuff I’m doing wrong? GOD please tell me!!! “cgitb” coud help you a bit for the debugging for python script.

“cgitb” is a module come with the standard python. It’s a traceback manager for CGI scripts. The origional design of the cgitb is use for display extensive traceback information in HTML for CGI scripts. Actually, it’s a special exception handler for python scripts. When you turn it on in your CGI script, you will get a detail report for what stuff make your script crash.

An example for a error cgi: http://ecom.cs.cityu.edu.hk/51142500/cgi/err.py.cgi

It’s easy to use the cgitb. Just insert the following code into the script top.

import cgitb; cgitb.enable()

It will automatically have the details report for those exception case and tell which part make your script crashed.

For further details:

  • http://effbot.org/pylib/cgi.htm#debugging-cgi-scripts
  • http://docs.python.org/lib/module-cgitb.html

Good luck for your CGI!

Filed under: Uncategorized