[英]Python requests add extra headers to HTTP GET
I am using python 2.7 requests module.我正在使用 python 2.7 请求模块。
I made this HTTP GET with the custom header below;我使用下面的自定义标头制作了这个 HTTP GET;
header ={
"projectName": "zhikovapp",
"Authorization": "Bearer HZCdsf="
}
response = requests.get(bl_url, headers = header)
The server returns a response that was not valid.服务器返回无效的响应。 On closer examination of the header that was sent, I discovered python requests module added some extra headers.
在仔细检查发送的标头后,我发现 python requests 模块添加了一些额外的标头。
{
'Accept-Encoding': 'gzip, deflate',
'projectName': 'zhikovapp',
'Accept': '*/*',
'User-Agent': 'python-requests/2.11.1',
'Connection': 'keep-alive',
'Authorization': 'Bearer HZCdsf='
}
The extra headers are Accept-Encoding
, Accept
, Connection
, User-Agent
.额外的标头是
Accept-Encoding
、 Accept
、 Connection
、 User-Agent
。 Is this a bug in python requests module?这是python请求模块中的错误吗? I am using requests ver 2.11.1
我正在使用 2.11.1 版的请求
How can I remove these extra headers added by python requests module?如何删除由 python requests 模块添加的这些额外标头?
you can do a prepared request.你可以做一个准备好的请求。
http://docs.python-requests.org/en/latest/user/advanced/#prepared-requests http://docs.python-requests.org/en/latest/user/advanced/#prepared-requests
then you can delete the headers manually然后您可以手动删除标题
del prepped.headers['Content-Type']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.