根据特定关键字查找所有 github 个存储库
Find all github repositories based on a specific keyword
我正在尝试使用 github 搜索 api 查找基于关键字 'TERRAGRUNT_VERSION' 的所有存储库并返回以下错误。我在 url 中遗漏了什么吗?
https://docs.github.com/en/rest/reference/search#search-repositories
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 3 column 1 (char 2)
代码:
import requests
token = "access_token=" + "23456789087"
base_api_url = 'https://api.github.com/'
search_final_url = base_api_url + 'search/repositories?q=TERRAGRUNT_VERSIONin:env/Makefile' + '&' + token
try:
response = requests.get(search_final_url).json()
for item in response['items']:
repo_name = item['name']
print(repo_name)
except Exception as e:
print(e)
问题是我收到了 400 响应。
我尝试了以下
response = requests.get("https://api.github.com/search/repositories?q=TERRAGRUNT_VERSIONin:env/Makefile&access_token=456744")
print(response)
Output:
<Response [400]>
{'message': 'Must specify access token via Authorization header. https://developer.github.com/changes/2020-02-10-deprecating-auth-through-query-param', 'documentation_url': 'https://docs.github.com/v3/#oauth2-token-sent-in-a-header'}
简而言之,您必须通过请求 header
而不是作为 url 参数传递 access_token
如果您尝试使用浏览器搜索 link,您会得到答案
{
"message": "Must specify access token via Authorization header. https://developer.github.com/changes/2020-02-10-deprecating-auth-through-query-param",
"documentation_url": "https://docs.github.com/v3/#oauth2-token-sent-in-a-header"
}
完整描述在 link 来自响应
我正在尝试使用 github 搜索 api 查找基于关键字 'TERRAGRUNT_VERSION' 的所有存储库并返回以下错误。我在 url 中遗漏了什么吗? https://docs.github.com/en/rest/reference/search#search-repositories
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 3 column 1 (char 2)
代码:
import requests
token = "access_token=" + "23456789087"
base_api_url = 'https://api.github.com/'
search_final_url = base_api_url + 'search/repositories?q=TERRAGRUNT_VERSIONin:env/Makefile' + '&' + token
try:
response = requests.get(search_final_url).json()
for item in response['items']:
repo_name = item['name']
print(repo_name)
except Exception as e:
print(e)
问题是我收到了 400 响应。 我尝试了以下
response = requests.get("https://api.github.com/search/repositories?q=TERRAGRUNT_VERSIONin:env/Makefile&access_token=456744")
print(response)
Output:
<Response [400]>
{'message': 'Must specify access token via Authorization header. https://developer.github.com/changes/2020-02-10-deprecating-auth-through-query-param', 'documentation_url': 'https://docs.github.com/v3/#oauth2-token-sent-in-a-header'}
简而言之,您必须通过请求 header
而不是作为 url 参数传递access_token
如果您尝试使用浏览器搜索 link,您会得到答案
{
"message": "Must specify access token via Authorization header. https://developer.github.com/changes/2020-02-10-deprecating-auth-through-query-param",
"documentation_url": "https://docs.github.com/v3/#oauth2-token-sent-in-a-header"
}
完整描述在 link 来自响应