I'm using zeep. The service I am using generates timeout errors every now and then, and I want to use automatic retry functionality.
I am trying to use a Requests retry session, but the timeout exception is not being caught and no retry is attempted.
I set up a Requests retry session (below) and I set up the client attribute of my class (currently with a timeout value to cause errors):
session = requests_retry_session()
transport = Transport(session=session,timeout=20,operation_timeout=.001)
self.client = Client(self.wsdl_url,transport=transport)
...
def requests_retry_session(
retries=10,
backoff_factor=0.3,
status_forcelist=(500, 502, 503, 504),
session=None,
) -> requests.Session:
session = session or requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
I'm getting a requests.exceptions.ReadTimeout (I assume this error is the same as the one I'm getting in real life, but with a 20s timeout, my logging is not good enough yet to be sure)
The exception is not being handled by the session.
Why not?
EDIT: zeep sends a POST request somewhere, which I did not find with my own debugging but activating debug logging in Requests shows it.
Retry does not work on POST by default.
https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html
I set method_whitelist=False to change that, and now I am triggering retries.