2

I am trying to find all repos based on a keyword 'TERRAGRUNT_VERSION' using github search api and its returning the below error. Am I missing something in the 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)

Code:

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)
  

The issue is I'm getting a 400 response. I tried the below

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'}
2
  • Well, so if it was not a /, can you show the response that you get from this search ? Commented Mar 17, 2022 at 21:13
  • I updated the question. I think i'm getting json decode error because the response body is empty. any thoughts on how to fix this? Commented Mar 17, 2022 at 21:15

1 Answer 1

2

In short, you have to pass access_token not as the url param but through the request header

If you try to search your link with browser, you would get the answer

{
  "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"
}

Full description is on the link from response

Sign up to request clarification or add additional context in comments.

2 Comments

It works after I passed the accesstoken as the request header. response = requests.get("api.github.com/search/repositories?q=TERRAGRUNT_VERSIONin:env/…", headers={'Authorization': '46788'})
So, if we solved your problem you can accept the answer ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.