Skip to content

Instantly share code, notes, and snippets.

@porthunt
Created August 6, 2021 19:49
  • Star 7 You must be signed in to star a gist
  • Fork 3 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?
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