python cgitb is not functioning through a browser

前提是你 提交于 2019-12-23 07:46:37

问题


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?


回答1:


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.




回答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



来源:https://stackoverflow.com/questions/19150013/python-cgitb-is-not-functioning-through-a-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!