python cgitb is not functioning through a browser
Asked Answered
M

2

10

I can't seem to get the python module cgitb to output the stack trace in a browser. I have no problems in a shell environment. I'm running Centos 6 with python 2.6.

Here is an example simple code that I am using:

import cgitb; cgitb.enable()

print "Content-type: text/html"
print

print 1/0

I get an Internal Server error instead of the printed detailed report. I have tried different error types, different browsers, etc.

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

Any Suggestions?

Movement answered 3/10, 2013 at 2:56 Comment(0)
N
6

Okay, I got my problem fixed and the OP brought me to it: Even tho cgitb will output HTML by default, it will not output a header! And Apache does not like that and might give you some stupid error like:

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

It indicates, that Apache was still working its way through the headers when it already encountered some HTML. Look at what the OP prints before the error is triggered. That is a header and you need that. Including the empty line.

Neville answered 15/11, 2017 at 10:33 Comment(0)
G
-2

I will just quote the docs:

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

Make sure that the first line of the script contains #! starting in column 1 followed by the pathname of the Python interpreter, for instance:

#!/usr/local/bin/python

Grijalva answered 6/6, 2015 at 7:15 Comment(3)
OP said, that with no error, the script runs fine. so it surely is not a problem with executing the CGI. Please comment on your answer in case i got it wrong because I, too, need to get this running and cgitb just does seem to catch and act on my problem.Neville
Let me not agree with you. In shell you may run the file by passing python in front of file name. In CGI you have to make sure the file itself is executable as CGI engine might not know how to run it. You have to put shebang-value in the beginning of the file.Grijalva
Agreed. However I find that the answer makes me think that this is the correct and only solution for the problem. Especially the "just". I think it should say "Please make sure that you have the CGI basics covered". I realize that I assume that there actually are different solutions to this problem in the OP's scenario.Neville

© 2022 - 2025 — McMap. All rights reserved.