Skip to content

Instantly share code, notes, and snippets.

@mxmader
Created April 6, 2017 21:12
  • Star 18 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Simple GitHub API example using python and personal access token
import requests
import json
####
# inputs
####
username = ''
# from https://github.com/user/settings/tokens
token = ''
repos_url = 'https://api.github.com/user/repos'
# create a re-usable session object with the user creds in-built
gh_session = requests.Session()
gh_session.auth = (username, token)
# get the list of repos belonging to me
repos = json.loads(gh_session.get(repos_url).text)
# print the repo names
for repo in repos:
print repo['name']
# make more requests using "gh_session" to create repos, list issues, etc.
@vishakhp
Copy link

This doesn't work anymore. {'message': 'Bad credentials', 'documentation_url': 'https://docs.github.com/rest'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment