As you know, Python CGI programming relies on the cgi and cgitb modules. Within the cgi module, however, is a little used function that you can use to create a CGI test script.
While debugging software is available for most web servers, such software often puts you out of control of the testing process. This is a program that you can use as a drop-in replacement for any CGI script that is not working. It is a great way of gathering the salient environment data without weeding your way through Apache's configuration or log files.
#!/usr/bin/pythonLet's take this apart line-by-line.
import sys
sys.stderr = sys.stdout
import os
from cgi import escape
print "Content-type: text/html"
print "<html><head><title>Situation snapshot</title></head><body><p>"
print "Running:"
print "<b>Python %s</b><br><br>" %(sys.version)
print "Environmental variables:<br>"
print "<ul>"
for k in sorted(os.environ):
print "<li><b>%s:</b>\t\t%s<br>" %(escape(k), escape(os.environ[k]))
print "</ul></p></body></html>"

