Skip to content

Commit

Permalink
l10n_fr_chorus_account: add timeout in HTTPs requests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexis-via committed Sep 18, 2023
1 parent b217b61 commit 5fc4f90
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion l10n_fr_chorus_account/models/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5fc4f90

Please sign in to comment.