简体   繁体   中英

Python requests add extra headers to HTTP GET

I am using python 2.7 requests module.

I made this HTTP GET with the custom header below;

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.

{
'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 . Is this a bug in python requests module? I am using requests ver 2.11.1

How can I remove these extra headers added by python requests module?

you can do a prepared request.

http://docs.python-requests.org/en/latest/user/advanced/#prepared-requests

then you can delete the headers manually

del prepped.headers['Content-Type']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM