VIPTELA SDWAN API call issue

295 views Asked by At

Need your expert advise on calling a API. 

i was trying to build a script for calling a devices information in Viptela SDWAN. At my home lab script worked as expected, but moment i changed the URL to live office Vmanage hosted on AWS, it gives me error and script was not able to login. however via internet explorer i was able to login into Vmanage GUI.

below is the configuration and error msgs i was getting. any advise will be helpful.

Error's:

Traceback (most recent call last):
File "C:/Users/XXXXXXX/Desktop/New folder (2)/apicallproject.py", line 123, in <module>
my_login()
File "C:/Users/XXXXXXX/Desktop/New folder (2)/apicallproject.py", line 24, in my_login
response = session.post(url=login_url, data=login_credentials, verify=false)
NameError: name 'false' is not defined

Process finished with exit code 1

+++++++++++++++With Verification set to true++++++++++++++++++++++

Traceback (most recent call last):
File "C:/Users/XXXXXXX/Desktop/New folder (2)/apicallproject.py", line 123, in <module>
my_login()
File "C:/Users/XXXXXXXX/Desktop/New folder (2)/apicallproject.py", line 24, in my_login
response = session.post(url=login_url, data=login_credentials, verify=true)
NameError: name 'true' is not defined

Process finished with exit code 1

Below is the python script which is working fine at my home LAB:-

ur = input ("Enter the path to Vmanage :")

name = input("Please enter your user name:")
passw = input("Please enter your password:")

def my_login():


login_url = '%s/j_security_check'%ur
login_credentials = {'j_username': name, 'j_password': passw}

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')
2

There are 2 answers

0
kranteg On

Using True or False should work. Perhaps due to different python version.

0
Baris Sonmez On

I made minor changes to your code and was able to run it in DevNet Sandbox Labs at version 20.4 You can try this code below in your environment.

import requests
import sys

requests.packages.urllib3.disable_warnings()

ur = input("Enter the path to Vmanage :")
name = input("Please enter your user name:")
passw = input("Please enter your password:")

def my_login():
  login_url = '%s/j_security_check' % ur
  login_credentials = {'j_username': name, 'j_password': passw}
  session = requests.session()
  response = session.post(url = login_url, data = login_credentials, verify=False)
  if b'<html>' in response.content:
    print(f"Login Failed, {response.status_code}")
    exit(0)
  else:
    print(f"Login Success, {response.status_code}")

my_login()

Enter the path to Vmanage :https://sandbox-sdwan-2.cisco.com

Please enter your user name:devnetuser

Please enter your password:RG!_Yw919_83

Login Success, 200