11-06-2023 06:59 AM
Ao executar o comando abaixo tenho a resposta de "Error Not Found", Cod:404.
Como posso descobrir o caminho correto para pegar o token?
https://vmanage.servicos.**/:8443/dataservice/client/token
Obrigado.
Solved! Go to Solution.
11-07-2023 02:46 AM
@sergiovianna see this page https://developer.cisco.com/docs/sdwan/#!authentication/how-to-authenticate
API requests header for GET/POST/PUT/DELETE are
class Authentication:
@staticmethod
def get_jsessionid(vmanage_host, vmanage_port, username, password):
api = "/j_security_check"
base_url = "https://%s:%s"%(vmanage_host, vmanage_port)
url = base_url + api
payload = {'j_username' : username, 'j_password' : password}
response = requests.post(url=url, data=payload, verify=False)
try:
cookies = response.headers["Set-Cookie"]
jsessionid = cookies.split(";")
return(jsessionid[0])
except:
print("No valid JSESSION ID returned\n")
exit()
@staticmethod
def get_token(vmanage_host, vmanage_port, jsessionid):
headers = {'Cookie': jsessionid}
base_url = "https://%s:%s"%(vmanage_host, vmanage_port)
api = "/dataservice/client/token"
url = base_url + api
response = requests.get(url=url, headers=headers, verify=False)
if response.status_code == 200:
return(response.text)
else:
return None
Auth = Authentication()
jsessionid = Auth.get_jsessionid(vmanage_host,vmanage_port,vmanage_username,vmanage_password)
token = Auth.get_token(vmanage_host,vmanage_port,jsessionid)
if token is not None:
header = {'Content-Type': "application/json",'Cookie': jsessionid, 'X-XSRF-TOKEN': token}
else:
header = {'Content-Type': "application/json",'Cookie': jsessionid}
11-07-2023 02:46 AM
@sergiovianna see this page https://developer.cisco.com/docs/sdwan/#!authentication/how-to-authenticate
API requests header for GET/POST/PUT/DELETE are
class Authentication:
@staticmethod
def get_jsessionid(vmanage_host, vmanage_port, username, password):
api = "/j_security_check"
base_url = "https://%s:%s"%(vmanage_host, vmanage_port)
url = base_url + api
payload = {'j_username' : username, 'j_password' : password}
response = requests.post(url=url, data=payload, verify=False)
try:
cookies = response.headers["Set-Cookie"]
jsessionid = cookies.split(";")
return(jsessionid[0])
except:
print("No valid JSESSION ID returned\n")
exit()
@staticmethod
def get_token(vmanage_host, vmanage_port, jsessionid):
headers = {'Cookie': jsessionid}
base_url = "https://%s:%s"%(vmanage_host, vmanage_port)
api = "/dataservice/client/token"
url = base_url + api
response = requests.get(url=url, headers=headers, verify=False)
if response.status_code == 200:
return(response.text)
else:
return None
Auth = Authentication()
jsessionid = Auth.get_jsessionid(vmanage_host,vmanage_port,vmanage_username,vmanage_password)
token = Auth.get_token(vmanage_host,vmanage_port,jsessionid)
if token is not None:
header = {'Content-Type': "application/json",'Cookie': jsessionid, 'X-XSRF-TOKEN': token}
else:
header = {'Content-Type': "application/json",'Cookie': jsessionid}
11-07-2023 06:14 AM
Thanks,
The documentation gave me an idea to inspect the page and so I took the correct path.
base_url = "https://%s"%(vmanage_host)
api = "dataservice/client/server"
However, now I'm running the code, and when I make a post I get a return of 500 Error: Internal Server Error.
I tested it on vmaneger's apidoc (swagger) and the error repeats itself.
11-07-2023 06:40 AM
@sergiovianna take a look at this, i wrote this sometime back https://github.com/bigevilbeard/Getting_Started_SDWAN - but has the information how to auth with SD-WAN API.
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