From 045dfb35768b2254f6b6a0af3bb82094d08d058b Mon Sep 17 00:00:00 2001 From: Guillaume Troupel Date: Fri, 8 Nov 2019 17:47:56 +0100 Subject: [PATCH] requests' session retry once to refresh TCP connection closed by Keycloak server fixes #36 --- keycloak/connection.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/keycloak/connection.py b/keycloak/connection.py index 3826936..5e166fc 100644 --- a/keycloak/connection.py +++ b/keycloak/connection.py @@ -27,6 +27,7 @@ except ImportError: from urlparse import urljoin import requests +from requests.adapters import HTTPAdapter from .exceptions import (KeycloakConnectionError) @@ -46,6 +47,10 @@ 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)) @property def base_url(self):