python - How to add header in requests -


is there other elegant way add header requests

requests.get(url,headers={'authorization', 'googlelogin auth=%s' % authorization_token)  

doesn't work while urllib2 worked

import urllib2  request = urllib2.request('http://maps.google.com/maps/feeds/maps/default/full') request.add_header('authorization', 'googlelogin auth=%s' % authorization_token) urllib2.urlopen(request).read() 

you can add custom headers requests request using following format uses python dictionary having colon, :, in syntax.

r = requests.get(url, headers={'authorization': 'googlelogin auth=%s' % authorization_token}) 

this presented in requests documentation custom headers follows:

>>> url = 'https://api.github.com/some/endpoint' >>> headers = {'user-agent': 'my-app/0.0.1'}  >>> r = requests.get(url, headers=headers) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -