我试图通过python请求访问github API(类似问题here和here的答案没有帮助)
使用curl,我可以获得一个项目最近提交的列表,例如
curl -H "Accept: application/vnd.github.inertia-preview+json Authorization: token a0d42faabef23ab5b5462394373fc133ca107890" https://api.github.com/repos/rsapkf/42/commit
尝试在python中对我尝试使用的请求使用相同的设置
url = "https://api.github.com/repos/rsapkf/42/commits"
headers = {"Accept": "application/vnd.github.inertia-preview+json", "Authorization": "token a0d42faabef23ab5b5462394373fc133ca107890"}
r = requests.get(url, headers=headers)
以及
url = "https://api.github.com/repos/rsapkf/42/commits"
headers = {"Accept": "application/vnd.github.inertia-preview+json"}
my_username = "someuser"
my_token = "a0d42faabef23ab5b5462394373fc133ca107890"
r = requests.get(url, headers=headers, auth=(my_username, my_token))
但在这两种情况下,我都得到了回应
{'documentation_url': 'https://docs.github.com/rest',
'message': 'Bad credentials'}
我错过了什么
不需要身份验证。以下工作:
相关问题 更多 >
编程相关推荐