forked from CiscoDevNet/dnac-python-path-trace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_token.py
30 lines (23 loc) · 870 Bytes
/
print_token.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /usr/bin/env python
from env_lab import apicem
import requests
import json
import urllib3
from requests.auth import HTTPBasicAuth
# Silence the insecure warning due to SSL Certificate
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
headers = {
'content-type': "application/json",
'x-auth-token': ""
}
def apic_login(host, username, password):
"""
Use the REST API to Log into an DNA_CENTER and retrieve token
"""
url = "https://{}/api/system/v1/auth/token".format(host)
# Make Login request and return the response body
response = requests.request("POST", url, auth=HTTPBasicAuth(username, password),
headers=headers, verify=False)
# print the token
print(response.text)
apic_login(apicem['host'], apicem['username'], apicem['password'])