Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The entire contents of my program:

import requests

# Make an API call and store the response.
url = 'https://api.github.com/search/repositories?=language:python&sort=stars'
# headers = {'Accept': 'application/vnd.github.v3+json'}
r = requests.get(url)
print(f"Status code: {r.status_code}")
# Store API response as a variable.
response_dict = r.json()

# Process results.
print(response_dict.keys())


Using python3 to run the program in terminal yields:

Status code: 422
dict_keys(['message', 'errors', 'documentation_url'])


The expected status code is 200. Can anyone tell me what I'm doing wrong, or if there is a good place to test this API call out?

What I have tried:

I've tried testing my API call at Online API Testing Tool | Test Your API Online[^]

and at

postman, where the response was:

    "message": "Validation Failed",
    "errors": [
        {
            "resource": "Search",
            "field": "q",
            "code": "missing"
        }
    ],
    "documentation_url": "https://docs.github.com/v3/search"
}


Not sure what I'm doing wrong, or really if I'm using the API testing tools correctly. Any help is appreciated, thank you!
Posted
Updated 17-Sep-21 22:23pm

422 Unprocessable Entity - HTTP | MDN[^]. The error message is telling you that the search parameter needs to be identified by a q charactger.
Try the following:
https://api.github.com/search/repositories?q=language:python&sort=stars[^].
 
Share this answer
 
Comments
Member 15355548 18-Sep-21 12:02pm    
This worked, thank you!
<pre lang="ASM">
remove422
<code>422<pre lang="CoffeeScript">error422status codediable 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900