获取对API的请求

2024-09-30 22:23:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试向特定api发出GET请求

import requests
import json

access_token = "71e89e8af02206575b3b4ae80bf35b6386fe3085af3d4085cbc7b43505084482"
url_base = "https://api.huntflow.ru/"

headers = {
  'User-Agent': 'App/1.0',
  'Host': 'api.huntflow.ru',
  'Content-Type': 'application/json',
  'Accept': '*/*',
  'Authorization': 'Bearer {0}'.format(access_token)
}

def test():
url = '{0}me'.format(url_base)

response = requests.get(url, headers=headers)

if response.status_code == 200:
    return json.loads(response.content.decode('utf-8'))
else:
    return response.json()


print(test())

输出: {'errors':[{'type':'oauth','value':['bad_authorization']}],'description':'Invalid access token'}

怎么了,告诉我


Tags: testimporttokenapijsonformaturlbase