From 1e806554b554b69bab03a1a8e82778994cccb2f3 Mon Sep 17 00:00:00 2001 From: Guillaume Troupel Date: Mon, 11 Nov 2019 11:23:42 +0100 Subject: [PATCH] Also retry on POST --- keycloak/connection.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/keycloak/connection.py b/keycloak/connection.py index 5e166fc..6f32439 100644 --- a/keycloak/connection.py +++ b/keycloak/connection.py @@ -47,10 +47,17 @@ class ConnectionManager(object): self._timeout = timeout self._verify = verify self._s = requests.Session() + # retry once to reset connection with Keycloak after tomcat's ConnectionTimeout # see https://github.com/marcospereirampj/python-keycloak/issues/36 - self._s.mount('https://', HTTPAdapter(max_retries=1)) - self._s.mount('http://', HTTPAdapter(max_retries=1)) + for protocol in ('https://', 'http://'): + adapter = HTTPAdapter(max_retries=1) + # adds POST to retry whitelist + method_whitelist = set(adapter.max_retries.method_whitelist) + method_whitelist.add('POST') + adapter.max_retries.method_whitelist = frozenset(method_whitelist) + + self._s.mount(protocol, adapter) @property def base_url(self):