我有一个使用 Gunicorn 和 nginx 部署的 Django 项目。我还运行了一个 memcached,并设置了 Django 缓存中间件 () 来缓存站点。
使用 DEBUG=True 运行时一切正常,但是当我切换到 DEBUG=False 时,尝试访问该站点时 Gunicorn 日志中出现以下错误:
2013-02-20 16:09:50 [25196] [ERROR] Error handling request
Traceback (most recent call last):
File "/home/toursprung/.virtualenvs/myproject/lib/python2.6/site-packages/gunicorn/workers/sync.py", line 102, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/home/toursprung/.virtualenvs/myproject/lib/python2.6/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
return self.application(environ, start_response)
File "/home/toursprung/.virtualenvs/myproject/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 247, in __call__
status_text = STATUS_CODE_TEXT[response.status_code]
AttributeError: 'NoneType' object has no attribute 'status_code'
奇怪的是,我在 Django 发送给我的错误电子邮件中收到另一个错误。在这里我得到以下信息:(GZIP 中间件中的错误。wtf?)
Traceback (most recent call last):
File "/home/toursprung/.virtualenvs/myproject/lib/python2.6/site-packages/django/core/handlers/base.py", line 188, in get_response
response = middleware_method(request, response)
File "/home/toursprung/.virtualenvs/myproject/lib/python2.6/site-packages/django/middleware/gzip.py", line 16, in process_response
if len(response.content) < 200:
File "/home/toursprung/.virtualenvs/myproject/lib/python2.6/site-packages/django/http/__init__.py", line 699, in _get_content
return ''.join([str(e) for e in self._container])
UnicodeEncodeError: 'ascii' codec can't encode character u'\x8b' in position 26: ordinal not in range(128)
有人知道为什么会这样吗?
提前致谢, 安东