Questions tagged «authorization-header»

5
Python请求:POST请求删除Authorization标头
我正在尝试使用Python请求库发出API POST请求。我正在通过Authorization标头,但是在尝试调试时,可以看到标头已被删除。我不知道发生了什么事。 这是我的代码: access_token = get_access_token() bearer_token = base64.b64encode(bytes("'Bearer {}'".format(access_token)), 'utf-8') headers = {'Content-Type': 'application/json', 'Authorization': bearer_token} data = '{"FirstName" : "Jane", "LastName" : "Smith"}' response = requests.post('https://myserver.com/endpoint', headers=headers, data=data) 如您在上方所见,我Authorization在请求参数中手动设置了标头,但它缺少实际请求的标头: {'Connection': 'keep-alive', 'Content-Type': 'application/json', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'User-Agent': 'python-requests/2.4.3 CPython/2.7.9 Linux/4.1.19-v7+'}。 另外一条信息是,如果我将POST请求更改为GET请求,则Authorization标头会正常通过! 为什么该库会丢弃POST请求的标头,如何使它正常工作? 使用请求库v2.4.3和Python 2.7.9
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.