0

我正在运行我的 djnago 应用程序使用 mod_wsg(由于某些原因,我不能使用内置的 django 服务器)

当发生错误并且我看到错误 500 时,我正在 /var/log/apache2/errors.log 中查找信息,但这里没有任何有用的信息。

如果我在语法、数据库或视图中有错误——随便!我收到有关“UnicodeDecodeError”的错误消息。它看起来像这样:

[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1] mod_wsgi (pid=10006): Exception occurred processing WSGI script '/hosting/mysite/public/django.wsgi'.
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]     response = self.get_response(request)
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 179, in get_response
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 221, in handle_uncaught_exception
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]     return debug.technical_500_response(request, *exc_info)
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 66, in technical_500_response
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]     html = reporter.get_traceback_html()
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 275, in get_traceback_html
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]     c = Context(self.get_traceback_data())
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 233, in get_traceback_data
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]     frames = self.get_traceback_frames()
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 387, in get_traceback_frames
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]     'vars': self.filter.get_traceback_frame_variables(self.request, tb.tb_frame),
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 183, in get_traceback_frame_variables
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]     value = self.get_request_repr(value)
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 102, in get_request_repr
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]     return build_request_repr(request, POST_override=self.get_post_parameters(request))
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/http/__init__.py", line 179, in build_request_repr
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1]     unicode(meta)))
[Mon Apr 30 00:21:48 2012] [error] [client 127.0.0.1] UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 1556: ordinal not in range(128)

我认为 django 尝试处理错误异常并在此过程中出现新错误。关于编码的东西。但我不知道如何解决它。

如何获取关于我的第一个错误的信息,而不是 UnicodeDecodeError?如何修复 UnicodeDecodeError?(修复它后,我希望在日志中看到我的第一个错误描述)。

4

1 回答 1

0

阅读有关此内容的 Django 文档:

https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#if-you-get-a-unicodeencodeerror

还可以尝试在 Django 设置模块中将 DEBUG 设置为 True。它可能允许在浏览器中显示底层错误。如果这是一个面向公众的站点并且您不能这样做,那么将 ADMINS 设置设置为 Django 文档中介绍的电子邮件地址,以便通过电子邮件将错误的详细信息发送给您。

于 2012-04-30T05:20:13.093 回答