相关疑难解决方法(0)

使用带有Python请求库的get方法的头文件

所以我最近偶然发现这个伟大的库在Python中处理HTTP请求; 在这里找到http://docs.python-requests.org/en/latest/index.html.

我喜欢使用它,但我无法弄清楚如何在我的获取请求中添加标题.救命?

python http-request python-requests

122
推荐指数
4
解决办法
22万
查看次数

如何在请求中添加标头

是否有任何其他优雅的方式为请求添加标头:

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)

python python-requests

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×2

python-requests ×2

http-request ×1