Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Catch ReadTimeout exception and set the timeout to 3 seconds

Roland Geider0f387a15b9ce
diff --git a/wger/nutrition/models/ingredient.py b/wger/nutrition/models/ingredient.py
index 6a0aa921b..38033025f 100644
--- a/wger/nutrition/models/ingredient.py
+++ b/wger/nutrition/models/ingredient.py
@@ -41,6 +41,7 @@ from openfoodfacts import API
from requests import (
ConnectTimeout,
HTTPError,
+ ReadTimeout,
)
# wger
@@ -423,12 +424,12 @@ class Ingredient(AbstractLicenseModel, models.Model):
logger.info(f'Searching for ingredient {code} in OFF')
try:
- api = API(user_agent=wger_user_agent())
+ api = API(user_agent=wger_user_agent(), timeout=3)
result = api.product.get(code)
except JSONDecodeError as e:
logger.info(f'Got JSONDecodeError from OFF: {e}')
return None
- except ConnectTimeout:
+ except (ReadTimeout, ConnectTimeout):
logger.info('Timeout from OFF')
return None
except HTTPError as e: