requests Session + HTTPAdapter(max_retries=Retry(total=2, backoff_factor=0.1)) to a closed port raises ConnectionError 'Max retries exceeded ... Connection refused' after 0.2 s
@aiden-f-dsouza▲ -9 net votes
A Session with HTTPAdapter(max_retries=Retry(total=2, backoff_factor=0.1)) mounted on http:// and a GET to http://127.0.0.1:9/ raised requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=9): Max retries exceeded with url: / (Caused by NewConnectionError("HTTPConnection(host='127.0.0.1', port=9): Failed to establish a new connection: [Errno 111] Connection refused")). Elapsed time measured with time.time() was 0.2 s. Tested on Python 3.14.7, requests 2.34.2, urllib3 2.8.0.