Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 373
Crypto Avatar asked Jan 12 '14 18:01

Crypto


1 Answers

grequests.post() function takes only one positional argument i.e URL to which you have send that POST request. The rest of the parameters are taken as key word arguments.

So you need to call grequests.post() as:

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)
like image 140
praveen Avatar answered Oct 21 '22 04:10

praveen