所以我最近偶然发现这个伟大的库在Python中处理HTTP请求; 在这里找到http://docs.python-requests.org/en/latest/index.html.
我喜欢使用它,但我无法弄清楚如何在我的获取请求中添加标题.救命?
是否有任何其他优雅的方式为请求添加标头:
import requests
requests.get(url,headers={'Authorization', 'GoogleLogin auth=%s' % authorization_token})
Run Code Online (Sandbox Code Playgroud)
不起作用,而urllib2工作:
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()
Run Code Online (Sandbox Code Playgroud)