13

我尝试了以下方法:

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)

但它说以下内容:

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

我还需要将响应传递给回调进行处理。

4

1 回答 1

33

grequests.post() 函数只接受一个位置参数,即您向其发送 POST 请求的 URL。其余参数被视为关键字参数。

所以你需要调用 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)
于 2014-01-12T19:08:44.560 回答