Skip to content

Commit afc8459

Browse files
authored
Merge pull request mattmakai#199 from huangsam/support-retries
Add support for request retries
2 parents ee2eb2a + cb2b7c8 commit afc8459

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

check_urls.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ def get_url_status(url):
6969
return (url, 0)
7070
clean_url = url.strip('?.')
7171
try:
72-
response = requests.get(
73-
clean_url, verify=False, timeout=10.0,
74-
headers={'User-Agent': URL_BOT_ID})
75-
return (clean_url, response.status_code)
72+
with requests.Session() as session:
73+
adapter = requests.adapters.HTTPAdapter(max_retries=10)
74+
session.mount('http://', adapter)
75+
session.mount('https://', adapter)
76+
response = session.get(
77+
clean_url, verify=False, timeout=10.0,
78+
headers={'User-Agent': URL_BOT_ID})
79+
return (clean_url, response.status_code)
7680
except requests.exceptions.Timeout:
7781
return (clean_url, 504)
7882
except requests.exceptions.ConnectionError:

0 commit comments

Comments
 (0)