Add timeouts to requests calls (#76851)

This commit is contained in:
Marc Mueller 2022-08-19 08:58:18 +02:00 committed by GitHub
parent 4eb4146e29
commit 1faabb8f40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 7 deletions

View file

@ -68,7 +68,7 @@ def check_box_health(url, username, password):
if username:
kwargs["auth"] = requests.auth.HTTPBasicAuth(username, password)
try:
response = requests.get(url, **kwargs)
response = requests.get(url, **kwargs, timeout=10)
if response.status_code == HTTPStatus.UNAUTHORIZED:
_LOGGER.error("AuthenticationError on %s", CLASSIFIER)
return None
@ -116,7 +116,9 @@ def post_image(url, image, username, password):
if username:
kwargs["auth"] = requests.auth.HTTPBasicAuth(username, password)
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:
_LOGGER.error("AuthenticationError on %s", CLASSIFIER)
return None
@ -137,6 +139,7 @@ def teach_file(url, name, file_path, username, password):
url,
data={FACEBOX_NAME: name, ATTR_ID: file_path},
files={"file": open_file},
timeout=10,
**kwargs,
)
if response.status_code == HTTPStatus.UNAUTHORIZED: