github代码搜索api总是返回404

2024-05-15 03:34:42 发布

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

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

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

但不幸的是,这并不好:

^{pr2}$

我的头看起来不错:

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

我再加上这个链接:

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

返回17个结果。在

我做错什么了?在


Tags: httpsgithubcomappsearchrequestsagentawesome
2条回答

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标头中指定此自定义媒体类型。在

您可能需要设置一个特殊的用户代理。http://developer.github.com/v3/#user-agent-required

编辑:您还必须根据此页在“接受”标题中提供自定义媒体类型:developer.github.com/v3/search在

相关问题 更多 >

    热门问题