Add timeouts to HTTP requests
This commit is contained in:
parent
00f0890021
commit
2eebe7d91e
3 changed files with 9 additions and 4 deletions
|
@ -489,7 +489,7 @@ class LuciDeviceScanner(object):
|
||||||
""" Perform one JSON RPC operation. """
|
""" Perform one JSON RPC operation. """
|
||||||
data = json.dumps({'method': method, 'params': args})
|
data = json.dumps({'method': method, 'params': args})
|
||||||
try:
|
try:
|
||||||
res = requests.post(url, data=data, **kwargs)
|
res = requests.post(url, data=data, timeout=5, **kwargs)
|
||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout:
|
||||||
self.logger.exception("Connection to the router timed out")
|
self.logger.exception("Connection to the router timed out")
|
||||||
return
|
return
|
||||||
|
|
|
@ -60,7 +60,7 @@ def setup(hass, download_path):
|
||||||
|
|
||||||
final_path = None
|
final_path = None
|
||||||
|
|
||||||
req = requests.get(url, stream=True)
|
req = requests.get(url, stream=True, timeout=10)
|
||||||
|
|
||||||
if req.status_code == 200:
|
if req.status_code == 200:
|
||||||
filename = None
|
filename = None
|
||||||
|
|
|
@ -74,14 +74,19 @@ class API(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if method == METHOD_GET:
|
if method == METHOD_GET:
|
||||||
return requests.get(url, params=data)
|
return requests.get(url, params=data, timeout=5)
|
||||||
else:
|
else:
|
||||||
return requests.request(method, url, data=data)
|
return requests.request(method, url, data=data, timeout=5)
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
logging.getLogger(__name__).exception("Error connecting to server")
|
logging.getLogger(__name__).exception("Error connecting to server")
|
||||||
raise ha.HomeAssistantError("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):
|
class HomeAssistant(ha.HomeAssistant):
|
||||||
""" Home Assistant that forwards work. """
|
""" Home Assistant that forwards work. """
|
||||||
|
|
Loading…
Add table
Reference in a new issue