Created
April 26, 2018 18:13
-
-
Save lenchevsky/b82f328f080fbf0983233f50fbfaee55 to your computer and use it in GitHub Desktop.
Use urllib2 if requests is not available
This file contains hidden or 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
#!/usr/bin/env python | |
import urllib2 | |
import ssl | |
import json | |
import os | |
SRV_CONTEXT = ssl.SSLContext(ssl.PROTOCOL_TLSv1) | |
# Configurable parameters | |
SRV_URL = "https://<URL>:<PORT>" | |
SRV_USR = "1" | |
SRV_PSW = "admin" | |
url = SRV_URL+'/api/v1/login' | |
data = json.dumps({ | |
"password": SRV_PSW, | |
"employeeId": SRV_USR | |
}) | |
req = urllib2.Request(url, data, { | |
"Content-Type": "application/json", | |
"X-Admin-UI": "script", | |
"User-Agent": "script", | |
}) | |
f = urllib2.urlopen(req, context=SRV_CONTEXT) | |
response = f.read() | |
f.close() | |
print response | |
print json.loads(response)['authToken'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment