cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
683
Views
5
Helpful
2
Replies

VMANAGE REST API AUTHENTICATION TO GET COOKIE SESSION

BlackAvatar
Level 1
Level 1

Hello Guys 

Please I am getting an error running the program from the Cisco Devnet repository "https://github.com/CiscoDevNet/Getting-started-with-Cisco-SD-WAN-REST-APIs" . Am getting the error below when I run the script against my production VMANAGE 

BlackAvatar_0-1665583646722.png

However the program works fine when I run it against the sandbox Vmanage on developer.cisco 

I'm running vmanage version 19.2.4 in production 

And the code below is from the original sdwan.py script that is giving the said error.

 

class Authentication:

@staticmethod
def get_jsessionid(vmanage_hostvmanage_portusernamepassword
api = "/j_security_check"
base_url = "https://%s:%s"%(vmanage_hostvmanage_port)
url = base_url + api
payload = {'j_username' : username'j_password' : password}
 
response = requests.post(url=urldata=payloadverify=False)
try:
cookies = response.headers["Set-Cookie"]
jsessionid = cookies.split(";")
return(jsessionid[0])
except:
if logger is not None:
logger.error("No valid JSESSION ID returned\n")
exit()

 

Can anyone help please 

 

2 Replies 2

Alexander Stevenson
Cisco Employee
Cisco Employee

Hi @BlackAvatar,

It might be just a problem with pasting your code, but it seems you're missing an ending parentheses at the end of the 'get_jsessionid' function, after the last parameter.

@BlackAvatar it works on the sandbox as this is using the new version of auth, which was released. 

 https://www.cisco.com/c/en/us/td/docs/routers/sdwan/configuration/sdwan-xe-gs-book/cisco-sd-wan-API-cross-site-request-forgery-prevention.html

You would need something like for older version auth.

 

import requests

login_url = 'https://[ipaddress]:8443/j_security_check'
login_credentials = {'j_username':'[username]', 'j_password':'[password]'}

session = requests.session()

response = session.post(url=login_url, data=login_credentials, verify=False)

if b'<html>' in response.content:
    print('Login Failed')
else:
    print('Login Success')

 

Hope this helps.

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