【发布时间】:2021-09-01 04:45:38
【问题描述】:
访问令牌每次都动态生成并传递给请求,它会抛出无效令牌错误。 访问令牌是动态传递和承载的,我不确定承载是正确的格式以在标头中发送令牌,请更正错误
import requests
Access_URL = 'https://host1/uaa/oauth/token'
client_id='ReadUser1'
client_secret='clientsecret1'
grant_type='client_credentials'
BASE_URL='https://host2/hisrian-rest-api/v1/tags?nameMask=*&maxNumber=500'
response = requests.post(Access_URL,
auth=(client_id, client_secret),
data=
{'grant_type':grant_type,'client_id':client_id,'client_secret':client_secret,'content-type': 'application/x-www-form-urlencoded'})
json_response=response.json()
tokenvalue= (json_response['access_token'])
headers={'Content-Type':'application/json',
'Authorization': Bearer {}".format(tokenvalue)}
auth_response = requests.get(BASE_URL, headers=headers)
print(auth_response.json())
【问题讨论】:
-
我认为问题是 BASE_URL。并且标头传递像(标头= {'Authorization':'Bearer' + tokenvalue,'Content-Type':'application/json'})
标签: python python-requests access-token rest