07-21-2024 08:49 PM
Hello,
For some reason, it appears that I am receiving the response for a token in request in html format indicated by the following error:
File "/usr/lib64/python3.9/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Below you will find an excerpt of the code:
#!/usr/bin/python
import requests
import json
import urllib3
from requests.auth import HTTPBasicAuth
urllib3.disable_warnings()
my_dna_ctr="sandboxdnac2.cisco.com"
my_user="devnetuser"
my_password="Cisco123!"
tkn_headers={"Content-Type": "application/json"}
my_tkn_uri="https://"+my_dna_ctr+"/dna/system/api/vi/auth/token"
my_tkn_req=requests.post(my_tkn_uri, auth=HTTPBasicAuth(my_user, my_password),headers=tkn_headers,verify=False)
my_access_token=my_tkn_req.json()["Token"]
:
I appreciate any help.
Thanks.
07-22-2024 01:02 AM - edited 07-22-2024 01:05 AM
hi @Netmart
First - seems like your URL is wrong. It should be /dna/system/api/v1/auth/token <- there is "v1" instead of "vi".
I tested your script and unfortunately there is a problem with authentication endpoint on dnac. I got response:
{
"error": "Basic Authorization is not allowed"
}
Seems like sandboxdnac2 has Basic auth disabled, because i tried to authenticate using GUI and Dev Toolkit - i got the same result.
BUT - you can use https://sandboxdnac.cisco.com/ without "2" and this will return you token with no issues so maybe this is the option?
The code with typo fixed:
#!/usr/bin/python
import requests
import json
import urllib3
from requests.auth import HTTPBasicAuth
urllib3.disable_warnings()
my_dna_ctr="sandboxdnac.cisco.com"
my_user="devnetuser"
my_password="Cisco123!"
tkn_headers={"Content-Type": "application/json"}
my_tkn_uri="https://"+my_dna_ctr+"/dna/system/api/v1/auth/token"
my_tkn_req=requests.post(my_tkn_uri, auth=HTTPBasicAuth(my_user, my_password),headers=tkn_headers,verify=False)
my_access_token=my_tkn_req.json()["Token"]
07-22-2024 03:10 AM
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide