Skip to content

Instantly share code, notes, and snippets.

@porthunt
Created August 6, 2021 19:49
Show Gist options
  • Save porthunt/b994154c054deeab7ab4073273aa75bc to your computer and use it in GitHub Desktop.
Save porthunt/b994154c054deeab7ab4073273aa75bc 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