2013-07-23 15 views
6

Widziałem to post o wysyłaniu asynchronicznych żądań z podskakującymi.Wyścigi w języku Python z niestandardowym nagłówkiem

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) 

Powiedzmy za jedyne jeden url, chciałem wysłać niestandardowy nagłówek:

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

Jak wysłać niestandardowy nagłówek dla jednego adresu URL za pomocą grequests?

Odpowiedz

7

Po prostu dodajesz nagłówek do argumentów, jak w przypadku request.get().

header = {'authorization' : '...'} 
rs = (grequests.get(u, headers=header) for u in urls) 
grequests.map(rs)