wsgi/web.py 浏览器中的正确错误输出
我正在使用 web.py 0.3 / apache2 / mod_wsgi 并且 cgitb 模块似乎不能开箱即用(我仍然只是从 web.py 得到“内部服务器错误”并且通常的输出转到 apache 的 error_log )。 web.py 安装指南建议了一种对我不起作用的解决方法 - 我可能可以破解它使其工作,但是我应该使用更好的东西(可能是为 web.py 或 wsgi 设计的)吗?
I'm using web.py 0.3 / apache2 / mod_wsgi and the cgitb module doesn't seem to work out of the box (I still just get 'internal server error' from web.py and the usual output goes to apache's error_log). The web.py install guide suggested a workaround which didn't work for me - I could probably hack it into working, but is there something better (perhaps designed for web.py or wsgi) that I should use instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在创建应用程序之前设置
web.config.debug = True
。这会启用调试错误,其中包含异常的堆栈跟踪以及局部变量的值。Set
web.config.debug = True
before creating your app. That enables debug error, which contains the stack trace of exception along with values of locals.调试 apache2 和 web.py 时,通常最好在 apache 错误日志中捕获错误。例如,当您收到内部服务器错误时,这意味着您的应用程序无论出于何种原因都没有返回任何内容。
在 Linux 上,我只是在单独的终端中查看错误日志...
或者
其他取决于您的发行版的东西。如果存在拼写错误或错误消息或其他什么情况,即使您在浏览器中收到内部服务器错误,您也会在错误日志中看到典型的 python 堆栈跟踪。
When debugging apache2 and web.py, it's usually good to catch errors in the apache error log. When you get an internal server error, for instance, it means nothing was returned for whatever reason by your app.
On Linux, I just watch the error log in a separate terminal...
or
or something depending on your distribution. If there's a typo or error message or what not, you'll get the typical python stack trace in your error log even if you get an internal server error in your browser.
缺乏 cgitb 也确实减慢了我的速度。这对我来说是这样:
尝试:
输出+=TroublesomeScript(等),
除了:
导入回溯;
Output+=str(traceback.format_exc())
如果您愿意,您可以美化输出,但这应该为您提供调试所需的信息。您也可以只输出 sys.exc_info(),但似乎建议使用回溯模块。
Lack of cgitb was really slowing me down, too. This did it for me:
try:
Output+=TroublesomeScript(etc)
except:
import traceback;
Output+=str(traceback.format_exc())
You can beautify the output if you like but this should give you the information you need for debugging. You can also just output sys.exc_info(), but the traceback module seems to be recommended.