Python 中的 HTTPS 会话重用
我希望能够对 HTTPS 服务器使用并行请求。目前,我正在使用 PyCURL,但它无法在不同句柄之间重用相同的 SSL 会话 ID,并且每个句柄每次只能处理一次下载/上传。
考虑到协商需要时间(特别是因为使用了客户端证书),重用 id(就像浏览器从 Web 并行下载少量资源时所做的那样)可能会提高性能。
那么,现在有人知道 PyCURL 的解决方法,或者支持它的替代 HTTP 模块吗? httplib 似乎也没有完成这项工作。
I would like to be able to use parallel requests to a HTTPS server. Currently, I am using PyCURL, but it isn't able of reusing the same SSL session ID between different handles, and each handle can only take care of one download/upload each time.
Taking into account the negotiation takes time (specially because client certificate is used), reusing the id (as browsers do for downloading few resources in parallel from a web) that would probably improve the performance.
So, does anybody now about some workaround for PyCURL, or an alternative HTTP module that supports that? httplib doesn't seem to do the work, either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如此处所述,目前无法轻松访问重用会话 ID,我还没有听说过任何简单的解决方案这 - 但这应该只是在初次握手后保存上下文并重用它的问题。
PyOpenSSL 公开了这些机制,但级别比大多数人想要的要低。我会把钱花在以下一系列事件上:
您可以打印出各种好的诊断内容(例如您的 SSL 会话 ID),以便您可以在当前问题的范围之外验证它。
一旦您了解了这一点,httplib 的 SSL 支持就非常简单了,HTTPSConnection 是 HTTPConnection 的一个非常薄的包装器(只有两个扩展该类的方法。您要修改的一个是 connect。
httplib.py - HTTPSConnection 类
Reusing session ids isn't currently easily accessible as noted here, I haven't heard of any simple solution for this - but it should just be a matter of saving your context after the initial handshake and reusing it.
PyOpenSSL exposes these mechanisms, but at a lower level than most people would want. I'd put my money on the following sequence of events:
You can print out all sorts of good diagnostic stuff (such as your SSL session id) just so you can verify it outside of the scope of your immediate problem.
Once you have that, httplib's SSL support is pretty simple, HTTPSConnection is a very thin wrapper around HTTPConnection (only two methods extending the class. The one you want to modify is connect.
httplib.py - HTTPSConnection class