Curl命令工作正常,而Python请求返回404

knpiaxh1  于 2022-11-13  发布在  Python
关注(0)|答案(1)|浏览(189)

curl

curl "https://api.wanikani.com/v2/summary" \ -H "Wanikani-Revision: 20170710" \ -H "Authorization: Bearer <API-KEY>"

此命令返回预期的json。
Python代码

import requests

headers = {"Wanikani-Revision": "20170710", "Authorization": "Bearer <API-KEY>"}
res = requests.post('https://api.wanikani.com/v2/summary', headers = headers)

print(res.text)

此代码返回404。{“错误”:“未找到”,“代码”:404}

brqmpdu1

brqmpdu11#

该函数只接受GET。请查看https://docs.api.wanikani.com/20170710/#summary
请尝试:

import requests

headers = {"Wanikani-Revision": "20170710", "Authorization": "Bearer <API-KEY>"}
 
res = requests.get('https://api.wanikani.com/v2/summary', headers = headers)

print(res.text)

相关问题