Skip to content

Instantly share code, notes, and snippets.

@LeoQuote
Created March 27, 2020 04:15
Show Gist options
  • Save LeoQuote/61d6c6d81745a4a75834054d7ce778ee to your computer and use it in GitHub Desktop.
Save LeoQuote/61d6c6d81745a4a75834054d7ce778ee to your computer and use it in GitHub Desktop.
import requests
import ssl
import json
import base64
github_base_url = 'https://api.github.com'
username = 'LeoQuote'
password = 'token'
org = 'LeoQuote'
repo = 'test-repo'
path = 'test-bin'
s = requests.session()
s.auth = (username, password)
bin_file = ssl.RAND_bytes(48)
print(len(bin_file))
s.put(f"{github_base_url}/repos/{org}/{repo}/contents/{path}",
data=json.dumps({
'message': 'add bin',
'content': base64.b64encode(bin_file).decode()
}))
r = s.get(f"{github_base_url}/repos/{org}/{repo}/contents/{path}")
content_github = base64.b64decode(r.json()['content'].encode())
print(len(content_github))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment