如何获取客户端paster/waitress应用的服务器堆栈跟踪

2 投票
1 回答
1040 浏览
提问于 2025-04-18 06:12

我正在运行一个用Python写的Pyramid应用程序,并且对它进行RESTful调用。这个应用是一个WSGI应用,使用Waitress作为HTTP服务器。目前,当我发出一个失败的HTTP请求时,我收到的错误信息是这样的:

Internal Server Error
The server encountered an unexpected internal server error

我该如何配置Waitress或Paster,以便能够看到像这样显示错误堆栈信息的错误:

Traceback (most recent call last):
  File "/.../pyramid/eggs/waitress-0.8.8-py2.7.egg/waitress/channel.py", line 337, in service
    task.service()
  File "/.../pyramid/eggs/waitress-0.8.8-py2.7.egg/waitress/task.py", line 173, in service
    self.execute()
  ...
  File "/.../pyramid/eggs/pyramid-1.4.5-py2.7.egg/pyramid/config/views.py", line 469, in _class_requestonly_view
    response = getattr(inst, attr)()
  File "/.../pyramid/dustin/views.py", line 139, in delete
    raise Exception('DELETE op failed; oid %s not found' % deleteItem)
Exception: DELETE op failed; oid 00x not found

我的Paster配置是:

[app:main]
use = egg:myegg

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.debug_templates = true
pyramid.default_locale_name = es

couchdb.uri = http://couchdb-host:5984/
couchdb.db = myegg

[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543

# Begin logging configuration

[loggers]
keys = root

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = INFO
handlers = console

[handler_console]
class = StreamHandler
args = [sys.stdout]
level = DEBUG
formatter = generic

[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s

# End logging configuration

1 个回答

1

你能不能用一个叫做异常视图的东西来捕捉所有的错误,并把错误的详细信息返回给用户呢?我之前用过类似的方法来捕捉我在Pyramid框架中的所有错误,记录下来,然后给用户展示一个“友好”的错误页面。

撰写回答