The adapter that you initialize set the Retry using below
if max_retries == DEFAULT_RETRIES:
self.max_retries = Retry(0, read=False)
else:
self.max_retries = Retry.from_int(max_retries)
And if you look at the initialization
def __init__(self, total=10, connect=None, read=None, redirect=None, status=None,
method_whitelist=DEFAULT_METHOD_WHITELIST, status_forcelist=None,
backoff_factor=0, raise_on_redirect=True, raise_on_status=True,
history=None, respect_retry_after_header=True):
The default value of respect_retry_after_header
is True
. You need this False
in your case. If you inspect the response using curl
$ curl -I http://www.etudes.ccip.fr/maintenance_site.php
HTTP/1.1 503 Service Temporarily Unavailable
Date: Thu, 23 Nov 2017 14:15:49 GMT
Server: Apache
Status: 503 Service Temporarily Unavailable
Retry-After: 3600
Expires: Sat, 26 Jul 1997 05:00:00 GMT
Cache-Control: pre-check=0, post-check=0, max-age=0
Pragma: no-cache
Connection: close
Content-Type: text/html; charset=ISO-8859-1
You want the respect_retry_after_header
to be set to False. This can be done by creating the adapter and then modifying this behavior
import requests
from requests.adapters import HTTPAdapter
url = 'http://www.etudes.ccip.fr/maintenance_site.php'
session = requests.Session()
adapter = HTTPAdapter(max_retries=2)
adapter.max_retries.respect_retry_after_header = False
session.mount('http://', adapter)
session.get(url, timeout=2)