Add timeouts to HTTP requests
This commit is contained in:
1 parent
00f0890021
commit
2eebe7d91e
3 files changed
+9
-4
No files matched your search
@@ -74,14 +74,19 @@ class API(object):
|
||||
|
||||
try:
|
||||
if method == METHOD_GET:
|
||||
return requests.get(url, params=data)
|
||||
return requests.get(url, params=data, timeout=5)
|
||||
else:
|
||||
return requests.request(method, url, data=data)
|
||||
return requests.request(method, url, data=data, timeout=5)
|
||||
|
||||
except requests.exceptions.ConnectionError:
|
||||
logging.getLogger(__name__).exception("Error connecting to server")
|
||||
raise ha.HomeAssistantError("Error connecting to server")
|
||||
|
||||
except requests.exceptions.Timeout:
|
||||
error = "Timeout when talking to {}".format(self.host)
|
||||
logging.getLogger(__name__).exception(error)
|
||||
raise ha.HomeAssistantError(error)
|
||||
|
||||
|
||||
class HomeAssistant(ha.HomeAssistant):
|
||||
""" Home Assistant that forwards work. """
|
||||
|
||||
Reference in new issue
Block a user