Skip to content

Instantly share code, notes, and snippets.

@waheedahmed
Last active January 10, 2020 13:44
Show Gist options
  • Save waheedahmed/ce986bb2429c712a3b822e921c0da3e1 to your computer and use it in GitHub Desktop.
Save waheedahmed/ce986bb2429c712a3b822e921c0da3e1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import requests
import threading
url = "http://edx.devstack.lms:18000/oauth2/access_token/"
client_id = "client-id"
payload_token = "grant_type=password&username={}&password={}&client_id={}".format("edx@example.com", "edx", client_id)
payload_refresh = "grant_type=refresh_token&refresh_token={}&client_id={}"
headers = {
'Content-Type': "application/x-www-form-urlencoded"
}
def request_token():
response = requests.request("POST", url,
data=payload_token,
headers=headers,
)
if int(response.status_code) == 200:
return response.json().get('refresh_token')
return None
def request_refresh():
response = requests.request("POST", url,
data=payload_refresh.format(token, client_id),
headers=headers)
print("refresh: {}".format(response.status_code))
print("response: {}".format(response.text.encode('utf-8')))
if __name__ == "__main__":
token = request_token()
t1 = threading.Thread(target=request_refresh)
t2 = threading.Thread(target=request_refresh)
t3 = threading.Thread(target=request_refresh)
t1.start()
t2.start()
t3.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment