I have a Django project deployed with Gunicorn and nginx. I also have a memcached running and the Django cache middleware () set up to cache the site.
Everything works fine when running with DEBUG=True, but when I switch to DEBUG=False I get the following error in Gunicorn log when trying to access the site:
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'
The strange thing is, that I get another error in the error email Django is sending me. Here I get the following: (An error in the GZIP Middleware. 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)
Anyone a clue why this is happening?
Thanks in advance, Anton
It was the ordering of my middlewares!
This is the ordering I had, which is wrong:
I moved the
GZipMiddleware
right below theUpdateCacheMiddleware
(ok, there is my little middleware that strips google analytics cookies in between) and now everything is working as expected.So this is the right order of middlewares:
Maybe this will help somebody in the future...