![](/img/trans.png)
[英]HTTP requests to Github Database API via Python keep returning 404
[英]How to access the github API via requests in python?
我正在尝试通过使用 python 的请求访问 github API(类似问题的答案在这里和这里没有帮助)。
使用 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'}
我在这里缺少什么?
不需要身份验证。 以下工作:
url = "https://api.github.com/repos/rsapkf/42/commits"
headers = {"Accept": "application/vnd.github.inertia-preview+json"}
r = requests.get(url, headers=headers)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.