gpt4 book ai didi

python - github代码搜索api总是返回404

转载 作者:行者123 更新时间:2023-11-30 23:33:57 25 4
gpt4 key购买 nike

根据docs我可以每分钟调用代码搜索 API 5 次,无需任何凭据。所以我应该能够使用 python requests:

import requests
user_agent = {'User-Agent': 'Awesome-Octocat-App'}
r = requests.get("https://api.github.com/search/repositories?q=chembl", headers=user_agent)

但不幸的是,这不行:

r.ok
>>> False
r.status_code
>>> 404

我的标题看起来不错:

r.request.headers
>>> {'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate, compress',
'Content-Length': '0',
'User-Agent': 'Awesome-Octocat-App'}

让我添加此链接:

https://github.com/search?q=chembl

返回 17 个结果。

那么我做错了什么?

最佳答案

GitHub 搜索 API 为 currently available in "preview mode" 。要在预览期间访问 API,您必须specify a custom media type in the Accept header :

application/vnd.github.preview

预览期允许开发人员测试新的 API,并在 API 被宣布稳定并适合生产使用之前与 GitHub 分享他们的反馈。预览期于2013年7月19日开始,预计持续约60天。在预览期结束时,您将不再需要在 Accept header 中指定此自定义媒体类型。

关于python - github代码搜索api总是返回404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18514157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com