如何通过python的httplib2.Http请求方法发布超过64K的数据?
如果我这样做:
h = httplib2.Http(timeout=60)
resp, content = h.request(uri, method=method, body=body, headers=headers,
redirections=redirections,
connection_type=connection_type)
如果正文超过 64K,则数据似乎被截断。
这是在 32 位 Python 运行时上发生的(我认为 64 位运行时不会发生这种情况)。
我该如何实现这个目标?
问题如下:
If I do this:
h = httplib2.Http(timeout=60)
resp, content = h.request(uri, method=method, body=body, headers=headers,
redirections=redirections,
connection_type=connection_type)
If body is more than 64K the data appears to be truncated.
This is on a 32-bit Python runtime (I don't think it happens with a 64-bit runttime).
How do I accomplish this?
Here's the issue:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我第一次听说这个。这是一个简短的程序,表明这对我有用。请注意,我运行的 full.cgi 脚本仅将请求标头和请求正文返回到响应正文中。当我运行这个完整的 64K+ 内容时,包括“结束”往返。
您确定在wireshark 中看到的不仅仅是TCP 段吗?这些将被截断为小于 64K,但不代表完整的 HTTP 请求。
First time I've ever heard of this. Here is a short program to show that this works for me. Note that the
full.cgi
script I have running just returns the request headers and request body back in the response body. When I run this the full 64K+ of content, including the ' the end' roundtrips.Are you sure you aren't seeing just the TCP segements in wireshark? Those would be truncated to less than 64K, but don't represent the full HTTP request.
该问题与未打补丁的 2.6.6 版本有关。换句话说,它与后来修复的已知错误有关。显然我得到了一个不包含此修复的 python 版本。
有关此问题的更多信息,请参阅此帖子:https://svn.macports.org/ticket/18376< /a>
修补版本设置 HAVE_POLL=0,强制 python 使用 select 代替。确保您使用的 python 版本包含此补丁,否则推送较大的数据块将会挂起。
另一个解决方案是重写 httplib.py 的 send 方法以捕获“35”异常并重新发送数据。
下面是一些代码来说明这一点:
代替 self.sock.sendall
The problem related to an unpatched build of 2.6.6. In other words, it relates to a known bug that was later fixed. Apparently I got a build of python that did not include this fix.
Please see this post for more info on this problem: https://svn.macports.org/ticket/18376
The patched version set HAVE_POLL=0, forcing python to use select instead. Make sure you are using a version of python that includes this patch, or pushing larger blocks of data will hang.
Another solution is a rewrite of the httplib.py's send method to catch the '35' exception and resend the data.
Here is some code that illustrates this:
in place of self.sock.sendall