CiscoDevNet/python-viptela

option to set proxy

pmraz123 opened this issue · 2 comments

Hello

I'm getting error when trying to access vmanage (CURL.wget) via CLI. Looks script doesnt use system proxy I found on my MAC.

XYZ@SKLSPMAC005 ~ % sudo networksetup -getwebproxy wi-fi
Password:
Enabled: Yes
Server: XYZ.XYZ.XYZ.XYZ.com
Port: 8000
Authenticated Proxy Enabled: 0

when I try any wget/curl this is not taken. Just when I use --proxy in wget/curl pages works.

The same is with python-viptela/vmanage SDK. via CLI I can not get to vmanage and getting error timeout.
(icmp works).

If we could set what proxy should be used in these SDKs - that would be awesome.

(I replaced some internal stuff by XYZ from security reasons)

(vmanage, username, passwd were exported...just i don want to share them).

XYZ@SKLSPMAC005 ~ % vmanage show device status
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 159, in _new_conn
conn = connection.create_connection(
File "/usr/local/lib/python3.8/site-packages/urllib3/util/connection.py", line 84, in create_connection
raise err
File "/usr/local/lib/python3.8/site-packages/urllib3/util/connection.py", line 74, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 978, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 309, in connect
conn = self._new_conn()
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 171, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x11538cc10>: Failed to establish a new connection: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 726, in urlopen
retries = retries.increment(
File "/usr/local/lib/python3.8/site-packages/urllib3/util/retry.py", line 439, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='vmanage-XYZ.viptela.net', port=443): Max retries exceeded with url: /dataservice/j_security_check (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x11538cc10>: Failed to establish a new connection: [Errno 61] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/XYZ/OneDrive - XYZ, Inc/Documents/att_projects/SDWAN/Cisco_SDWAN/API/python-viptela/vmanage/api/authentication.py", line 65, in login
response = self.session.post(url=url,
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 578, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='vmanage-XYZ.viptela.net', port=443): Max retries exceeded with url: /dataservice/j_security_check (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x11538cc10>: Failed to establish a new connection: [Errno 61] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/bin/vmanage", line 33, in
sys.exit(load_entry_point('viptela', 'console_scripts', 'vmanage')())
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 829, in call
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context().obj, *args, **kwargs)
File "/Users/XYZ/OneDrive - XYZ, Inc/Documents/att_projects/SDWAN/Cisco_SDWAN/API/python-viptela/vmanage/cli/show/device.py", line 23, in status
vmanage_device = Device(ctx.auth, ctx.host, ctx.port)
File "/Users/XYZ/OneDrive - XYZ, Inc/Documents/att_projects/SDWAN/Cisco_SDWAN/API/python-viptela/vmanage/main.py", line 37, in auth
self.__auth = Authentication(host=self.host, port=self.port, user=self.username,
File "/Users/XYZ/OneDrive - XYZ, Inc/Documents/att_projects/SDWAN/Cisco_SDWAN/API/python-viptela/vmanage/api/authentication.py", line 84, in login
raise Exception(f'Could not connect to {self.host}: {e}')
Exception: Could not connect to vmanage-XYZ.viptela.net: HTTPSConnectionPool(host='vmanage-XYZ.viptela.net', port=443): Max retries exceeded with url: /dataservice/j_security_check (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x11538cc10>: Failed to establish a new connection: [Errno 61] Connection refused'))

XYZ@SKLSPMAC005 ~ % ping vmanage-XYZ.viptela.net
PING vmanage-XYZ.viptela.net (XYZ): 56 data bytes
64 bytes from XYZ: icmp_seq=0 ttl=33 time=144.315 ms
64 bytes from XYZ: icmp_seq=1 ttl=33 time=143.112 ms
64 bytes from XYZ: icmp_seq=2 ttl=33 time=151.929 ms
64 bytes from XYZ: icmp_seq=3 ttl=33 time=149.090 ms
^C
--- vmanage-XYZ.viptela.net ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 143.112/147.112/151.929/3.569 ms
XYZ@SKLSPMAC005 ~ %

i built my own where is possible to use proxy or go direct. Disregard this request

@pmraz123 did you want to submit a PR for this functionality?