Posted By

freephys on 12/18/09


Tagged

traceback


Versions (?)

Debugging/logging CGI script in Python


 / Published in: Python
 

  1. import sys, traceback
  2. print "Content-type: text/html\n\n"
  3. try: # use explicit exception handling
  4. import my_cgi # main CGI functionality in 'my_cgi.py'
  5. my_cgi.main()
  6. except:
  7. import time
  8. errtime = '--- '+ time.ctime(time.time()) +' ---\n'
  9. errlog = open('cgi_errlog', 'a')
  10. errlog.write(errtime)
  11. traceback.print_exc(None, errlog)
  12. print "<html>\n<head>"
  13. print "<title>CGI Error Encountered!</title>\n</head>"
  14. print "<body><p>A problem was encountered running MyCGI</p>"
  15. print "<p>Please check the server error log for details</p>"
  16. print "</body></html>"

Report this snippet  

You need to login to post a comment.