Timeout if Tomato router does not respond for 1 sec

This commit is contained in:
Paulus Schoutsen 2013-10-23 23:58:48 +01:00
parent 05472481c5
commit 7443a5f963

View File

@ -318,7 +318,7 @@ class TomatoDeviceScanner(object):
self.logger.info("Tomato:Scanning") self.logger.info("Tomato:Scanning")
try: try:
response = requests.Session().send(self.req) response = requests.Session().send(self.req, timeout=1)
# Calling and parsing the Tomato api here. We only need the # Calling and parsing the Tomato api here. We only need the
# wldev and dhcpd_lease values. For API description see: # wldev and dhcpd_lease values. For API description see:
@ -343,7 +343,7 @@ class TomatoDeviceScanner(object):
return False return False
except requests.ConnectionError: except requests.exceptions.ConnectionError:
# We get this if we could not connect to the router or # We get this if we could not connect to the router or
# an invalid http_id was supplied # an invalid http_id was supplied
self.logger.exception(("Tomato:Failed to connect to the router" self.logger.exception(("Tomato:Failed to connect to the router"
@ -351,6 +351,14 @@ class TomatoDeviceScanner(object):
return False return False
except requests.exceptions.Timeout:
# We get this if we could not connect to the router or
# an invalid http_id was supplied
self.logger.exception(("Tomato:Connection to the router "
"timed out"))
return False
except ValueError: except ValueError:
# If json decoder could not parse the response # If json decoder could not parse the response
self.logger.exception(("Tomato:Failed to parse response " self.logger.exception(("Tomato:Failed to parse response "