Skip to content
Snippets Groups Projects
Commit 5dc9655b authored by Emanuele Aina's avatar Emanuele Aina
Browse files

test_urls: Use a session to retry requests


We often get DNS resolution or connection failures, try a few time
before giving up.

Signed-off-by: Emanuele Aina's avatarEmanuele Aina <emanuele.aina@collabora.com>
parent cd82ee49
No related branches found
No related tags found
1 merge request!278Speedup test_urls
......@@ -82,6 +82,11 @@ headers={
"User-Agent" : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
}
session = requests.Session()
adapter = requests.adapters.HTTPAdapter(max_retries=3)
session.mount('http://', adapter)
session.mount('https://', adapter)
broken = []
for url in urls:
print("%s : " %(url), end='')
......@@ -90,7 +95,7 @@ for url in urls:
status = None
resp = None
try:
resp = requests.head(url, headers=headers, allow_redirects=True, timeout=60, verify=False)
resp = session.head(url, headers=headers, allow_redirects=True, timeout=60, verify=False)
status = resp.ok
resp.close()
except Exception as e:
......@@ -102,7 +107,7 @@ for url in urls:
# that's not got a 200 status code with GET as well.
if not status:
resp = None
resp = requests.get(url, headers=headers, allow_redirects=True, timeout=60, verify=False)
resp = session.get(url, headers=headers, allow_redirects=True, timeout=60, verify=False)
status = resp.ok
resp.close()
except Exception as e:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment