Skip to content

Instantly share code, notes, and snippets.

@mxmader
Created April 6, 2017 21:12
Show Gist options
  • Save mxmader/8281851a99d0cfb53a363286246c08d8 to your computer and use it in GitHub Desktop.
Save mxmader/8281851a99d0cfb53a363286246c08d8 to your computer and use it in GitHub Desktop.
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