Authentication fails when vMananage port number is something other than 443
aq5747 opened this issue · 1 comments
I've been trying to use this SDK against the Cisco always-on Sandbox (https://sandboxsdwan.cisco.com:8443) and it was consistently failing, even after setting port=8443 when calling Authentication, something like this:
vmanage_host = 'sandboxsdwan.cisco.com'
vmanage_username = 'devnetuser'
vmanage_password = 'Cisco123!'
vmanage_port = 8443
auth = Authentication(host=vmanage_host, user=vmanage_username, port=vmanage_port,
password=vmanage_password, validate_certs=False).login()
However when doing this I get the following Traceback, and you can see the port number is still 443.
Traceback (most recent call last):
File "/home/queena2/scripts/vmanage_api_test.py", line 21, in <module>
password=vmanage_password, validate_certs=False).login()
File "/home/queena2/scripts/vmanage_api_bug/.venv/lib/python3.6/site-packages/vmanage/api/authentication.py", line 75, in login
version = Utilities(self.session, self.host).get_vmanage_version()
File "/home/queena2/scripts/vmanage_api_bug/.venv/lib/python3.6/site-packages/vmanage/api/utilities.py", line 48, in get_vmanage_version
response = HttpMethods(self.session, url).request('GET')
File "/home/queena2/scripts/vmanage_api_bug/.venv/lib/python3.6/site-packages/vmanage/api/http_methods.py", line 81, in request
raise Exception(f'Connection error to {self.url}: {e}')
Exception: Connection error to https://sandboxsdwan.cisco.com:443/dataservice/system/device/controllers?model=vmanage&&&&: HTTPSConnectionPool(host='sandboxsdwan.cisco.com', port=443): Max retries exceeded with url: /dataservice/system/device/controllers?model=vmanage&&&& (Caused by ProxyError('Cannot connect to proxy.', timeout('_ssl.c:835: The handshake operation timed out',)))
It appears that in authentication.py that it calls Utilities to get the current vManage version (as 19.2.x has to be handled a bit differently), but the custom port number isn't passed into Utilities and thus it defaults to 443. Since the server isn't running on this port the connection fails.
version = Utilities(self.session, self.host).get_vmanage_version()
Changing the line above to insert port=self.port appears to fix the issue.
version = Utilities(self.session, self.host, port=self.port).get_vmanage_version()
Change has been merged into master and will be included in the next release.