@@ -38,6 +38,8 @@ def myrequests_get(url, params=None, headers=None, cdx=False, allow404=False):
38
38
headers ['User-Agent' ] = 'pypi_cdx_toolkit/' + __version__
39
39
40
40
retry = True
41
+ retry_sec = 1
42
+ retry_max_sec = 30
41
43
retries = 0
42
44
connect_errors = 0
43
45
while retry :
@@ -58,6 +60,7 @@ def myrequests_get(url, params=None, headers=None, cdx=False, allow404=False):
58
60
# 503=slow down, 50[24] are temporary outages, 500=Amazon S3 generic error
59
61
# CC takes a 503 from storage and then emits a 500 with error text in resp.text
60
62
# I have never seen IA or CC send 429 or 509, but just in case...
63
+ # 429 is also a slow down, IA started sending them mid-2023
61
64
retries += 1
62
65
if retries > 5 :
63
66
LOGGER .warning ('retrying after 1s for %d' , resp .status_code )
@@ -67,7 +70,8 @@ def myrequests_get(url, params=None, headers=None, cdx=False, allow404=False):
67
70
LOGGER .info ('retrying after 1s for %d' , resp .status_code )
68
71
if resp .text :
69
72
LOGGER .info ('response body is %s' , resp .text )
70
- time .sleep (1 )
73
+ time .sleep (retry_sec )
74
+ retry_sec = min (retry_sec * 2 , retry_max_sec )
71
75
continue
72
76
if resp .status_code in {400 , 404 }: # pragma: no cover
73
77
if resp .text :
@@ -90,7 +94,8 @@ def myrequests_get(url, params=None, headers=None, cdx=False, allow404=False):
90
94
if connect_errors > 10 :
91
95
LOGGER .warning (string )
92
96
LOGGER .info ('retrying after 1s for ' + str (e ))
93
- time .sleep (1 )
97
+ time .sleep (retry_sec )
98
+ retry_sec = min (retry_sec * 2 , retry_max_sec )
94
99
except requests .exceptions .RequestException as e : # pragma: no cover
95
100
LOGGER .warning ('something unexpected happened, giving up after %s' , str (e ))
96
101
raise
0 commit comments