-
-
Save mcfearsome/b36edd362674e14720c4d5061d6a33a3 to your computer and use it in GitHub Desktop.
Read json file from a private GitHub repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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