mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Add timeouts to requests calls (#76851)
This commit is contained in:
parent
4eb4146e29
commit
1faabb8f40
@ -74,7 +74,9 @@ class AbodeCamera(AbodeDevice, Camera):
|
|||||||
"""Attempt to download the most recent capture."""
|
"""Attempt to download the most recent capture."""
|
||||||
if self._device.image_url:
|
if self._device.image_url:
|
||||||
try:
|
try:
|
||||||
self._response = requests.get(self._device.image_url, stream=True)
|
self._response = requests.get(
|
||||||
|
self._device.image_url, stream=True, timeout=10
|
||||||
|
)
|
||||||
|
|
||||||
self._response.raise_for_status()
|
self._response.raise_for_status()
|
||||||
except requests.HTTPError as err:
|
except requests.HTTPError as err:
|
||||||
|
@ -68,7 +68,7 @@ def check_box_health(url, username, password):
|
|||||||
if username:
|
if username:
|
||||||
kwargs["auth"] = requests.auth.HTTPBasicAuth(username, password)
|
kwargs["auth"] = requests.auth.HTTPBasicAuth(username, password)
|
||||||
try:
|
try:
|
||||||
response = requests.get(url, **kwargs)
|
response = requests.get(url, **kwargs, timeout=10)
|
||||||
if response.status_code == HTTPStatus.UNAUTHORIZED:
|
if response.status_code == HTTPStatus.UNAUTHORIZED:
|
||||||
_LOGGER.error("AuthenticationError on %s", CLASSIFIER)
|
_LOGGER.error("AuthenticationError on %s", CLASSIFIER)
|
||||||
return None
|
return None
|
||||||
@ -116,7 +116,9 @@ def post_image(url, image, username, password):
|
|||||||
if username:
|
if username:
|
||||||
kwargs["auth"] = requests.auth.HTTPBasicAuth(username, password)
|
kwargs["auth"] = requests.auth.HTTPBasicAuth(username, password)
|
||||||
try:
|
try:
|
||||||
response = requests.post(url, json={"base64": encode_image(image)}, **kwargs)
|
response = requests.post(
|
||||||
|
url, json={"base64": encode_image(image)}, timeout=10, **kwargs
|
||||||
|
)
|
||||||
if response.status_code == HTTPStatus.UNAUTHORIZED:
|
if response.status_code == HTTPStatus.UNAUTHORIZED:
|
||||||
_LOGGER.error("AuthenticationError on %s", CLASSIFIER)
|
_LOGGER.error("AuthenticationError on %s", CLASSIFIER)
|
||||||
return None
|
return None
|
||||||
@ -137,6 +139,7 @@ def teach_file(url, name, file_path, username, password):
|
|||||||
url,
|
url,
|
||||||
data={FACEBOX_NAME: name, ATTR_ID: file_path},
|
data={FACEBOX_NAME: name, ATTR_ID: file_path},
|
||||||
files={"file": open_file},
|
files={"file": open_file},
|
||||||
|
timeout=10,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
if response.status_code == HTTPStatus.UNAUTHORIZED:
|
if response.status_code == HTTPStatus.UNAUTHORIZED:
|
||||||
|
@ -66,6 +66,6 @@ class AutomateNotificationService(BaseNotificationService):
|
|||||||
"payload": message,
|
"payload": message,
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post(_RESOURCE, json=data)
|
response = requests.post(_RESOURCE, json=data, timeout=10)
|
||||||
if response.status_code != HTTPStatus.OK:
|
if response.status_code != HTTPStatus.OK:
|
||||||
_LOGGER.error("Error sending message: %s", response)
|
_LOGGER.error("Error sending message: %s", response)
|
||||||
|
@ -142,7 +142,7 @@ class NestCamera(Camera):
|
|||||||
url = self.device.snapshot_url
|
url = self.device.snapshot_url
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(url)
|
response = requests.get(url, timeout=10)
|
||||||
except requests.exceptions.RequestException as error:
|
except requests.exceptions.RequestException as error:
|
||||||
_LOGGER.error("Error getting camera image: %s", error)
|
_LOGGER.error("Error getting camera image: %s", error)
|
||||||
return None
|
return None
|
||||||
|
@ -87,7 +87,7 @@ def _create_processor_from_config(hass, camera_entity, config):
|
|||||||
def _get_default_classifier(dest_path):
|
def _get_default_classifier(dest_path):
|
||||||
"""Download the default OpenCV classifier."""
|
"""Download the default OpenCV classifier."""
|
||||||
_LOGGER.info("Downloading default classifier")
|
_LOGGER.info("Downloading default classifier")
|
||||||
req = requests.get(CASCADE_URL, stream=True)
|
req = requests.get(CASCADE_URL, stream=True, timeout=10)
|
||||||
with open(dest_path, "wb") as fil:
|
with open(dest_path, "wb") as fil:
|
||||||
for chunk in req.iter_content(chunk_size=1024):
|
for chunk in req.iter_content(chunk_size=1024):
|
||||||
if chunk: # filter out keep-alive new chunks
|
if chunk: # filter out keep-alive new chunks
|
||||||
|
@ -134,7 +134,7 @@ class UkTransportSensor(SensorEntity):
|
|||||||
{"app_id": self._api_app_id, "app_key": self._api_app_key}, **params
|
{"app_id": self._api_app_id, "app_key": self._api_app_key}, **params
|
||||||
)
|
)
|
||||||
|
|
||||||
response = requests.get(self._url, params=request_params)
|
response = requests.get(self._url, params=request_params, timeout=10)
|
||||||
if response.status_code != HTTPStatus.OK:
|
if response.status_code != HTTPStatus.OK:
|
||||||
_LOGGER.warning("Invalid response from API")
|
_LOGGER.warning("Invalid response from API")
|
||||||
elif "error" in response.json():
|
elif "error" in response.json():
|
||||||
|
@ -503,6 +503,7 @@ class ConfigEntryWithingsApi(AbstractWithingsApi):
|
|||||||
f"{self.URL}/{path}",
|
f"{self.URL}/{path}",
|
||||||
params=params,
|
params=params,
|
||||||
headers={"Authorization": f"Bearer {access_token}"},
|
headers={"Authorization": f"Bearer {access_token}"},
|
||||||
|
timeout=10,
|
||||||
)
|
)
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user