python 请求无法使用带有承载令牌的访问令牌

python requests not working with access token with bearer token

访问令牌每次都动态生成并传递给请求,它会抛出无效令牌错误。 访问令牌是动态传递和承载的,我不确定承载的格​​式是否正确以 header 发送令牌,请更正错误

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())

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=100'
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 = {'Authorization': 'Bearer ' +
       tokenvalue, 'Content-Type': 'application/json'}
auth_response = requests.get(BASE_URL,  headers=headers)
print(auth_response.json())