4

我正在用 Django 1.6 和 Python 3.4 编写一个演示代理服务器。当响应包含此标头时出现错误:

Transfer-Encoding=chunked

错误是:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
    return self.application(environ, start_response)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 214, in __call__
    start_response(force_str(status), response_headers)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wsgiref/handlers.py", line 236, in start_response
    assert not is_hop_by_hop(name),"Hop-by-hop headers not allowed"
AssertionError: Hop-by-hop headers not allowed

我发现了这个问题:Allow hop-by-hop headers in Django proxy middleware但似乎 Django 1.6 没有basehttp._hop_headers.

我用python3.4 manage.py runserver.

请帮忙

4

1 回答 1

8

The following HTTP/1.1 headers are hop-by-hop headers that wsgiref does not allowed:

  - Connection
  - Keep-Alive
  - Proxy-Authenticate
  - Proxy-Authorization
  - TE
  - Trailers
  - Transfer-Encoding
  - Upgrade

See:

  1. Hypertext Transfer Protocol -- HTTP/1.1
  2. The code of wsgiref: util.py, handlers.py

于 2014-10-18T13:38:08.663 回答