Created
November 21, 2022 14:44
-
-
Save HalCanary/a1f704274aaa40740949a094b42b3356 to your computer and use it in GitHub Desktop.
rest.py
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 urllib.request | |
import urllib.parse | |
import json | |
################################################################################ | |
def Get(auth, host, path, query={}): | |
q = urllib.parse.urlencode(query) | |
req = urllib.request.Request( | |
f"https://{host}{path}?{q}", | |
headers={"Authorization": auth}) | |
with urllib.request.urlopen(req) as r: | |
return json.loads(r.read()) | |
def Post(auth, host, path, query={}): | |
req = urllib.request.Request( | |
f"https://{host}{path}", | |
data=bytes(json.dumps(query), 'UTF-8'), | |
headers={ | |
"Authorization": auth, | |
"Content-Type": "application/json"}) | |
with urllib.request.urlopen(req) as r: | |
return json.loads(r.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment