Friday, March 13, 2009

Python CGI Debugging howto

I found this useful when you are trying to debug a python script running on a remote server (that has a previous version of python, in my case :( ).

To show the classic interpreter error messages just do this:

import sys
sys.stderr = sys.stdout

print "Content-type: text/html\n"


In this way, we set the errors to output text on the standard output (in other words, we redirect the errors to the standard output), then we print the standard HTTP header to inform the browser that the following text will be an HTML page (even text/plain works fine) and if we get an error, it will be in some part of the page source :D.

Simple, probably not the best, but it works.

No comments:

Post a Comment