Skip to content

Commit 1e80655

Browse files
author
Guillaume Troupel
committed
Also retry on POST
1 parent 045dfb3 commit 1e80655

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

keycloak/connection.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,17 @@ def __init__(self, base_url, headers={}, timeout=60, verify=True):
4747
self._timeout = timeout
4848
self._verify = verify
4949
self._s = requests.Session()
50+
5051
# retry once to reset connection with Keycloak after tomcat's ConnectionTimeout
5152
# see https://github.com/marcospereirampj/python-keycloak/issues/36
52-
self._s.mount('https://', HTTPAdapter(max_retries=1))
53-
self._s.mount('http://', HTTPAdapter(max_retries=1))
53+
for protocol in ('https://', 'http://'):
54+
adapter = HTTPAdapter(max_retries=1)
55+
# adds POST to retry whitelist
56+
method_whitelist = set(adapter.max_retries.method_whitelist)
57+
method_whitelist.add('POST')
58+
adapter.max_retries.method_whitelist = frozenset(method_whitelist)
59+
60+
self._s.mount(protocol, adapter)
5461

5562
@property
5663
def base_url(self):

0 commit comments

Comments
 (0)