简体   繁体   English

使用python-requests管道化POST请求

[英]Pipelining POST requests with python-requests

Assuming that I can verify that a bunch of POST requests are in fact logically independent, how can I set up HTTP pipelining using python-requests and force it to allow POST requests in the pipeline? 假设我可以验证一堆POST请求实际上在逻辑上是独立的,那么如何使用python-requests设置HTTP流水线并强制其允许管道中的POST请求?

Does someone have a working example? 有人有可行的榜样吗?

PS for extra points, how to handle errors for outstanding requests if pipeline suddenly breaks? PS加分,如果管道突然中断,如何处理未决请求的错误?

PPS grequests is not an option in this case. 在这种情况下,不能选择PPS grequests

Pipelining requests can be done with the builtin httplib, but only by accessing the connection and response objects below their public interface. 可以使用内置的httplib来完成流水线请求,但是只能通过访问其公共接口下的连接和响应对象来完成。 This snippet demonstrates. 此片段演示。

The requests library does not support HTTP pipelining . requests不支持HTTP流水线

You can approximate pipelining by using grequests which makes it easier to run many requests in parallel, but each parallel request would still use a new TCP connection. 您可以使用grequests 近似流水线化,这使得并行运行许多请求变得更加容易,但是每个并行请求仍将使用新的TCP连接。

( requests does pool connections, keeping the TCP connection open if the remote server permits this, but that only helps for sequential connections, and request and response still have to alternate). requests会建立池连接,如果远程服务器允许,则保持TCP连接处于打开状态,但这仅有助于顺序连接,并且请求和响应仍然必须交替)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM