Python requests & urllib3 Retry - How to simulate a ConnectionError from inside the internal retry loop?

Viewed 315

Given following example usage:

adapter = HTTPAdapter(max_retries=Retry(
    total=5,
    backoff_factor=0.1,
    status_forcelist=[429, 500, 502, 503, 504],
    method_whitelist=["HEAD", "GET", "OPTIONS"]
))
session = requests.Session()
session.mount("http://", adapter)
session.mount("https://", adapter)
rsp = session.post(url, json=my_json, params=my_params)

I occasionally get:

('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

I would like to establish retries around this as well (related question), and I'd like to be able to test it by issuing such an error from inside the library's retry loop.

How do I do that?

0 Answers
Related