File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44
55[project ]
66name = " cardo-python-utils"
7- version = " 0.5.7 "
7+ version = " 0.5.8 "
88description = " Python library enhanced with a wide range of functions for different scenarios."
99readme = " README.rst"
1010requires-python = " >=3.8"
Original file line number Diff line number Diff line change 66
77import json
88import os
9+ import time
910import requests
1011
1112from django .conf import settings
@@ -125,10 +126,17 @@ def get_oidc_confidential_client_token(**kwargs) -> dict:
125126 data ["client_assertion_type" ] = KEYCLOAK_CLIENT_ASSERTION_TYPE
126127 data ["client_assertion" ] = get_confidential_client_service_account_token ()
127128
128- response = requests .post (
129- get_oidc_op_token_endpoint (),
130- data = data ,
131- )
129+ max_retries = 3
130+ for attempt in range (max_retries + 1 ):
131+ response = requests .post (
132+ get_oidc_op_token_endpoint (),
133+ data = data ,
134+ )
135+ # Retry on server errors (5xx), it might be a temporary issue with Keycloak.
136+ if response .status_code < 500 or attempt == max_retries :
137+ break
138+ time .sleep (2 ** attempt ) # 1, 2, 4 seconds
139+
132140 response .raise_for_status ()
133141
134142 return response .json ()
You can’t perform that action at this time.
0 commit comments