Last active
January 15, 2018 09:42
-
-
Save sergiomario/62621605a17ff82e1908c6a48142fc10 to your computer and use it in GitHub Desktop.
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 json | |
import requests | |
BASE_URL = 'https://10.0.0.1/cgi-bin' | |
API = { | |
'login': BASE_URL+'/api/v1/system/login', | |
} | |
headers = {'content-type': 'application/json'} | |
def auth(username, password): | |
data = {'data': {'username': username, 'password': password}} | |
response = requests.post(API['login'], data=json.dumps(data), | |
headers=headers, verify=False) | |
if response.status_code == 200: | |
token = json.loads(response.content.decode('utf-8'))['data']['Token'] | |
headers['Authorization'] = 'Bauer ' + token | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment