kbr / fritzconnection

Python-Tool to communicate with the AVM Fritz!Box by the TR-064 protocol and the AHA-HTTP-Interface
MIT License
303 stars 59 forks source link

ConnectionError exception from requests not trapped #128

Closed chemelli74 closed 2 years ago

chemelli74 commented 2 years ago

The following trace should be catch and should be catch and raised as FritzConnectionException.

Reference trace:

File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/fritzconnection.py", line 155, in __init__
self.device_manager.add_description(source)
File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/devices.py", line 75, in add_description
root = get_xml_root(source, timeout=self.timeout, session=self.session)
File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/utils.py", line 59, in get_xml_root
source = get_content_from(source, timeout=timeout, session=session)
File "/usr/local/lib/python3.9/site-packages/fritzconnection/core/utils.py", line 41, in get_content_from
with session.get(url, timeout=timeout) as response:
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 555, in get
return self.request('GET', url, **kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.1.3', port=49000): Max retries exceeded with url: /igddesc.xml (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fad67c1c0>: Failed to establish a new connection: [Errno 113] Host is unreachable'))
kbr commented 2 years ago

Reading the traceback the underlying ConnectionPool of urllib3 connection instances seems to run out of connections. I suppose the real problem is elsewhere: can it be that the library is flooded with connection requests?

kbr commented 2 years ago

Or did you unplug the router? Some more context would be helpful.

chemelli74 commented 2 years ago

Or did you unplug the router? Some more context would be helpful.

Router unplugged, in the end of the trace the info is "Failed to establish a new connection: [Errno 113] Host is unreachable')".

Simone

kbr commented 2 years ago

Ok, but this is kind of a UserError :) Never got this in all the years – however, we can catch this.

kbr commented 2 years ago

covered with 1.8.0