Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python grequests with custom header

I saw this post about sending asynchronous requests with grequests.

import grequests

urls = [
    'http://www.heroku.com',
    'http://tablib.org',
    'http://httpbin.org',
    'http://python-requests.org',
    'http://kennethreitz.com'
]

rs = (grequests.get(u) for u in urls)
grequests.map(rs)

Let's say for just one of the url, I wanted to send a custom header:

header = {'authorization' : '...'}

How would I send a custom header for one url using grequests?

like image 754
Yau Avatar asked Jul 23 '13 15:07

Yau


1 Answers

You simply include the header in the arguments like you would with requests.get().

header = {'authorization' : '...'}
rs = (grequests.get(u, headers=header) for u in urls)
grequests.map(rs)
like image 106
Marcel Wilson Avatar answered Nov 17 '22 20:11

Marcel Wilson