Skip to content

Instantly share code, notes, and snippets.

@sergiomario
Last active January 15, 2018 09:42
Show Gist options
  • Save sergiomario/62621605a17ff82e1908c6a48142fc10 to your computer and use it in GitHub Desktop.
Save sergiomario/62621605a17ff82e1908c6a48142fc10 to your computer and use it in GitHub Desktop.
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