You can add headers by passing a dictionary as an argument.
This should work:
requests.get(url,headers={'Authorization': 'GoogleLogin auth=%s' % authorization_token})
Why your code not worked?
You were not passing a dictionary to the headers argument. You were passing values according to the format defined in add_header()
function.
According to docs,
requests.get(url, params=None, headers=None, cookies=None, auth=None,
timeout=None)
headers – (optional) Dictionary of HTTP Headers to send with the
Request.
Why request.add_header() worked?
Your way of adding headers using request.add_header()
worked because the function is defined as such in the urllib2
module.
Request.add_header(key, val)
It accepts two arguments -
- Header name (key of dict defined earlier)
- Header value(value of the corresponding key in the dict defined earlier)