Skip to content

Instantly share code, notes, and snippets.

Created September 22, 2023 16:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Use `pip install requests` before running.
import requests
# replace 'YOUR_GITHUB_USERNAME' with your GitHub username
github_username = 'YOUR_GITHUB_USERNAME'
# github API endpoint to retrieve user information
api_url = f'{github_username}'
# send a GET request to the GitHub API
response = requests.get(api_url)
# check if the request was successful (status code 200)
if response.status_code == 200:
# parse the JSON response
user_data = response.json()
# print some user information
print(f"github username: {user_data['login']}")
print(f"name: {user_data['name']}")
print(f"bio: {user_data['bio']}")
print(f"followers: {user_data['followers']}")
print(f"following: {user_data['following']}")
print(f"public repositories: {user_data['public_repos']}")
# print an error message if the request was not successful
print(f"request failed with status code {response.status_code}")
except requests.exceptions.RequestException as e:
# handle any exceptions that may occur during the request
print(f"an error occurred: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment