Skip to content

Instantly share code, notes, and snippets.

@taylortaurus
Forked from porthunt/read_github_json.py
Created October 15, 2021 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taylortaurus/9fcad6f83236d2d69734de98d167607f to your computer and use it in GitHub Desktop.
Save taylortaurus/9fcad6f83236d2d69734de98d167607f to your computer and use it in GitHub Desktop.
Read json file from a private GitHub repository
import base64
import json
import requests
REPO_URL = "https://api.github.com/repos/<USER>/<REPO>/contents/<PATH>/<TO>/<FILE>.json"
TOKEN = "<YOUR PAT OR OAUTH TOKEN>"
headers = {
"Authorization": f"token {TOKEN}",
"Accept": "application/vnd.github.v4+raw"
}
response = requests.get(REPO_URL, headers=headers)
if response and response.status_code == 200:
binary_content = base64.b64decode(response.json()["content"])
content = binary_content.decode("utf-8")
json = json.loads(content)
print(json)
else:
print(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment