10-22-2020 01:46 AM
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')
10-22-2020 03:12 AM
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
10-27-2020 05:03 AM
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?
10-27-2020 07:08 AM
There was no change in the auth API between those two versions.
Hope this helps.
10-29-2020 12:38 AM
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
10-29-2020 03:56 AM
Did you try using the code i posted above, does this work in both environments once you have updated the URL/US/Password?
10-30-2020 04:52 AM
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'))
10-30-2020 06:00 AM
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.
11-09-2020 12:38 AM
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?
11-09-2020 06:24 AM
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
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