【发布时间】:2012-08-18 22:27:30
【问题描述】:
我在处理 http 分块传输编码时遇到问题。
我正在使用:
- 阿帕奇。
- mod_wsgi 插件。
- django.
django 只能处理带有 content-length 头域的常规 http 请求,但在处理 TE(Transfer-Encoding)、chunked 或 gzip 时,它会返回一个空结果。
我正在考虑两种方法:
- 对 django.wsgi python 文件进行一些修改
- 在 django 中添加一些中间件 python 文件,以拦截任何分块的 http 请求,将其转换为带有 content-length 头字段的 requelar http 请求,然后将其传递给 django,它可以很好地处理它。
任何人都可以提供以上 2 个选项中的任何一个(当然欢迎更多选项)
谢谢!
这是格雷厄姆第一次回答后对我的问题的延伸:
首先,感谢您的快速回复。使用的客户端是 Axis,它是另一家公司与我们的系统通信的一部分。我设置了WSGIChunkedRequest On,我还对我的 wsgi 包装器进行了一些修改,如下所示:
def application(environ, start_response):
if environ.get("mod_wsgi.input_chunked") == "1":
stream = environ["wsgi.input"]
print stream
print 'type: ', type(stream)
length = 0
for byte in stream:
length+=1
#print length
environ["CONTENT_LENGTH"] = len(stream.read(length))
django_application = get_wsgi_application()
return django_application(environ, start_response)
但它给了我那些错误(从 apache 的 error.log 文件中提取):
[Sat Aug 25 17:26:07 2012] [error] <mod_wsgi.Input object at 0xb6c35390>
[Sat Aug 25 17:26:07 2012] [error] type: <type 'mod_wsgi.Input'>
[Sat Aug 25 17:26:08 2012] [error] [client xxxxxxxxxxxxx] mod_wsgi (pid=27210): Exception occurred processing WSGI script '/..../wsgi.py'.
[Sat Aug 25 17:26:08 2012] [error] [client xxxxxxxxxxxxx] Traceback (most recent call last):
[Sat Aug 25 17:26:08 2012] [error] [client xxxxxxxxxxxxx] File "/..../wsgi.py", line 57, in application
[Sat Aug 25 17:26:08 2012] [error] [client xxxxxxxxxxxxx] for byte in stream:
[Sat Aug 25 17:26:08 2012] [error] [client xxxxxxxxxxxxx] IOError: request data read error
我做错了什么?!
【问题讨论】:
-
还要补充一点:
environ["CONTENT_LENGTH"] = len(stream.read())效果不佳,并给出了与IOError: request data read error相同的错误..谢谢!
标签: django apache mod-wsgi wsgi chunked-encoding