cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
420
Views
4
Helpful
3
Replies

Falha no get_token API SDWAN

sergiovianna
Level 1
Level 1

Ao executar o comando abaixo tenho a resposta de "Error Not Found", Cod:404.

    @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

Como posso descobrir o caminho correto para pegar o token?
https://vmanage.servicos.**/:8443/dataservice/client/token
Obrigado.

1 Accepted Solution

Accepted Solutions

@sergiovianna see this page https://developer.cisco.com/docs/sdwan/#!authentication/how-to-authenticate

API requests header for GET/POST/PUT/DELETE are

  • For vManage pre-19.2 - Session Cookie (jsessionid)
  • For vManage post-19.2 - Session Cooke (jsessionid) and Token
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}

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

View solution in original post

3 Replies 3

@sergiovianna see this page https://developer.cisco.com/docs/sdwan/#!authentication/how-to-authenticate

API requests header for GET/POST/PUT/DELETE are

  • For vManage pre-19.2 - Session Cookie (jsessionid)
  • For vManage post-19.2 - Session Cooke (jsessionid) and Token
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}

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

sergiovianna
Level 1
Level 1
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.

@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.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Review Cisco Networking for a $25 gift card