无法在python请求中发布授权标头

时间:2020-10-28 13:01:08

标签: python python-3.x python-requests

我一直试图将有效负载发布到端点,该端点需要承载令牌。 使用python请求,我正在尝试将标头中的不记名令牌发布为

from requests import Session

http= Session()

accessToken = getToken(url=uri,data=payload)

authorization_header_string = 'bearer ' + accessToken

requestHeaders = {"Content-type": "text/plain", "Authorization":authorization_header_string}
         

headerData={"content-type":"text/plain","authorization":requestHeaders}

resp= http.post(url=uri,data=payload,headers=headerData)

但是我得到的只是401错误,而如果我在邮递员中使用相同的令牌,则可以正常工作。 我正在使用requestbin检查其中的授权有时仅出现在标题中。

1 个答案:

答案 0 :(得分:0)

尝试以下操作:

token = "your token"

headerData={"content-type": "text/plain", "authorization": "Bearer " + token}