Python cgitb not working through browser

I cannot get the python cgitb module to display the stack trace in the browser. I have no problems in the shell environment. I am running Centos 6 with python 2.6.

Here is an example of simple code that I use:

import cgitb; cgitb.enable() print "Content-type: text/html" print print 1/0 

I get an internal server error instead of a printed verbose report. I tried different types of errors, different browsers, etc.

When I have no error, of course, python works fine. It will print an error in a thin shell. The point of cgitb is to print an error instead of returning "Internal Server Error" in the browser for most errors. Basically, I'm just trying to get cgitb to work in a browser environment.

Any suggestions?

+7
python internal-server-error
source share
2 answers

Well, my problem is fixed, and the OP led me to it: even cgitb will output the default HTML, it will not display the title! And Apache doesn't like this and may give you some kind of dumb error, for example:

<...blablabla>: Response header name '<!--' contains invalid characters, aborting request

This indicates that Apache was still breaking through the headers when it was already encountering some HTML. See what the OP prints before the error is triggered. This is the headline, and you need it. Including an empty string.

0
source share

I will just give the docs :

Make sure your script is readable and executable by "others"; Unix file mode should be 0755 octal (use chmod 0755 filename ).

Make sure the first line of the script contains #! starting at column 1 followed by the path to the Python interpreter, for example:

#!/usr/local/bin/python

-one
source share

All Articles