我在Windows下的Mongoose web服务器(v5.6)上通过CGI使用Python。我能够得到一个CGI脚本来执行,但只要有错误,我就会在浏览器中得到一个空白页面。我尝试使用下面的简单脚本强制执行错误,但无论是否启用cgitb,我都没有得到任何输出。如何获取预期的错误回溯信息?
#!C:\Program Files\Python 2.7.10\python.exe
import cgitb; cgitb.enable()
print "Content-type: text/html\n"
print "<html><body>Hello World</body></html>"
#Script works as expected without the unmatched quote below.
print "发布于 2016-01-24 19:49:23
只有当您拥有有效的python脚本时,才能使用cgitb。当你在一个常规的python解释器中运行你的脚本时,你的脚本根本不会被执行,你会说这样的话:
File "./test.py", line 8
print "
^
SyntaxError: Missing parentheses in call to 'print'如果您的python脚本不能执行,cgitb就没有机会将错误正确地放入输出文件中。
https://stackoverflow.com/questions/31267489
复制相似问题