简体   繁体   English

如何使用grequests发出HTTP POST请求

[英]How do I make HTTP POST requests with grequests

I tried the following: 我尝试了以下方法:

import grequests

urls = ['http://localhost/test', 'http://localhost/test']

params = {'a':'b', 'c':'d'}
rs = (grequests.post(u, params) for u in urls)
grequests.map(rs)

But it says the following: 但它说如下:

File "search.py", line 6, in <genexpr>
rs = (grequests.post(u, params) for u in urls)
TypeError: __init__() takes exactly 3 arguments (4 given)

I also need to pass the response to a callback for processing. 我还需要将响应传递给回调进行处理。

grequests.post() function takes only one positional argument ie URL to which you have send that POST request. grequests.post()函数只接受一个位置参数,即您发送该POST请求的URL。 The rest of the parameters are taken as key word arguments. 其余参数被视为关键字参数。

So you need to call grequests.post() as: 所以你需要调用grequests.post()为:

import grequests

urls = ['http://localhost/test', 'http://localhost/test']

params = {'a':'b', 'c':'d'}
rs = (grequests.post(u, data=params) for u in urls)
grequests.map(rs)

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

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