cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2206
Views
0
Helpful
9
Replies

Viptela Vmanage API calling issue

jonlink01
Level 1
Level 1

Hi All,

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

9 Replies 9

Are you using the same version in both environments? In vManage version 19.2+ a token is required to be sent in the headers with every request. Here is an example of this https://developer.cisco.com/codeexchange/github/repo/bigevilbeard/Getting_Started_SDWAN

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

Home LAB have Vmanage version 19.2,  and in office live network its 20.X.X. do you think this can be a problem?

script I created working absolutely fine, but in live network its creating an issue.  

 

do you think, their is any policy configured on the office network which is blocking to setup a session?

There was no change in the auth API between those two versions.

 

Hope this helps.

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

I understand that it wont have any auth difference, any advise why i cant able to login via same script. why its giving below error and what can i do to resolve it...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

Did you try using the code i posted above, does this work in both environments once you have updated the URL/US/Password?

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

Its not working, 

 

script which i wrote is working fine on my home lab and sandbox lab. but its giving an error moment i change the IP address of Vmanage to my live network.

 

it gives below error:

 

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='XXXXXX.com', port=XXX): Max retries exceeded with url: /j_security_check (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x037E5C70>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time or established connection failed because connected host has failed to respond'))

There is your issue, [WinError 10060] TCP error code 10060 is usually caused by DNS issues or by a port being blocked.

 

Hope this helps.

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

When i am using postman i am able to get the details from API. but when i tried to get the details from API via phthon 3, it gives error.

 

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='XXXXXX.com', port=XXX): Max retries exceeded with url: /j_security_check (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x037E5C70>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time or established connection failed because connected host has failed to respond'))

 

can you guide how can i call the details via python?

 

 

Check your Postman collection is using the same port, i don't think this is the issue as the error output you have provided does not match, but worth checking.

 

I got your code to work, but it had a few errors. You can try this on this device also.

 

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()

 

(venv) STUACLAR-M-R6EU:Desktop stuaclar$ python sdwan_tester.py 
Enter the path to Vmanage :https://sandbox-sdwan-1.cisco.com
Please enter your user name:devnetuser
Please enter your password:RG!_Yw919_83
Login Success, 200
Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io