I have some strange behavior in Python. I created a Python script to get VLAN information from a 2930F switch. The script is very basic:
- Collect admin credentials
- Log in and get the cookie
- Perform Python requests to get VLANs
- Print JSON output
- Log off
I added the script as an attachment. I have 3 2930F switches with similar configuration. The script gets the VLANs for 1 of the 3 switches. Only a VLAN GET doesn't work on the 2 switches. As soon as I change to GET url to, for example: get_vlan = requests.get(url + vlans-ports, headers=headers, verify=False, timeout=2) the script works. I can change vlans-ports for many other variables, like system, lldp or whatever, they all work. Only vlans doesn't work.
I don't get any useful information from a debug rest-interface on the switch. Visual Studio Code gives me some output, that you can find below.
Strange thing for me is that the switches have the same config, same firmware version.
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\site-packages\urllib3\response.py", line 360, in _error_catcher
yield
File "C:\Program Files\Python37\lib\site-packages\urllib3\response.py", line 685, in read_chunked
line = self._fp.fp.readline()
File "C:\Program Files\Python37\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "C:\Program Files\Python37\lib\ssl.py", line 1052, in recv_into
return self.read(nbytes, buffer)
File "C:\Program Files\Python37\lib\ssl.py", line 911, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\site-packages\requests\models.py", line 750, in generate
for chunk in self.raw.stream(chunk_size, decode_content=True):
File "C:\Program Files\Python37\lib\site-packages\urllib3\response.py", line 490, in stream
for line in self.read_chunked(amt, decode_content=decode_content):
File "C:\Program Files\Python37\lib\site-packages\urllib3\response.py", line 694, in read_chunked
self._original_response.close()
File "C:\Program Files\Python37\lib\contextlib.py", line 130, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Program Files\Python37\lib\site-packages\urllib3\response.py", line 365, in _error_catcher
raise ReadTimeoutError(self._pool, None, 'Read timed out.')
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='10.10.1.2', port=443): Read timed out.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:/cloudstation/github/hpe-aos-cli/vlan_add.py", line 80, in <module>
get_vlan = requests.get(url + 'vlans', headers=headers, verify=False, timeout=2)
File "C:\Program Files\Python37\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\requests\api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\requests\sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "C:\Program Files\Python37\lib\site-packages\requests\sessions.py", line 686, in send
r.content
File "C:\Program Files\Python37\lib\site-packages\requests\models.py", line 828, in content
self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b''
File "C:\Program Files\Python37\lib\site-packages\requests\models.py", line 757, in generate
raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='10.10.1.2', port=443): Read timed out.