From 5fc4f90197e999cebea2af943b1c3f1e41bcc5da Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 18 Sep 2023 17:36:42 +0200 Subject: [PATCH] l10n_fr_chorus_account: add timeout in HTTPs requests --- l10n_fr_chorus_account/models/company.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/l10n_fr_chorus_account/models/company.py b/l10n_fr_chorus_account/models/company.py index 82462fa0a..c14c1bd6e 100644 --- a/l10n_fr_chorus_account/models/company.py +++ b/l10n_fr_chorus_account/models/company.py @@ -25,6 +25,7 @@ TOKEN_URL = "https://oauth.piste.gouv.fr/api/oauth/token" QUALIF_TOKEN_URL = "https://sandbox-oauth.piste.gouv.fr/api/oauth/token" MARGIN_TOKEN_EXPIRY_SECONDS = 240 +TIMEOUT = 30 class ResCompany(models.Model): @@ -159,6 +160,7 @@ def _get_new_token(self, oauth_id, oauth_secret, qualif): "client_secret": oauth_secret, "scope": "openid", }, + timeout=TIMEOUT, ) logger.debug("_get_new_token HTTP answer code=%s", r.status_code) except requests.exceptions.ConnectionError as e: @@ -257,7 +259,11 @@ def chorus_post(self, api_params, url_path, payload, session=None): logger.info("Payload of the Chorus POST request: %s", payload) try: r = session.post( - url, verify=True, data=json.dumps(payload), headers=headers + url, + verify=True, + data=json.dumps(payload), + headers=headers, + timeout=TIMEOUT, ) except requests.exceptions.ConnectionError as e: logger.error("Connection to %s failed. Error: %s", url, e)