Skip to content

Instantly share code, notes, and snippets.

Created October 31, 2019 03:38
What would you like to do?
access api with jwt
import json
from urllib.request import urlopen
from urllib.request import Request
from urllib.parse import urlencode
# set username, password, auth_url, api_url
params = urlencode({"username": username, "password": password}).encode()
# get token
request = Request(auth_url, params)
with urlopen(request) as response:
token = json.loads(["token"]
# access
request = Request(api_url, None, {
'Authorization': "JWT %s" % token
response = urlopen(request).read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment