How to make HTTP POST requests using 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 he 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 the callback for processing.

+8
python grequests
source share
1 answer

The grequests.post () function accepts only one positional argument to which you sent this POST request. The remaining parameters are accepted as keyword arguments.

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

 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) 
+20
source

All Articles