Skip to content

Commit 338918b

Browse files
author
Jonathan Falkenstein
authored
Merge pull request #3 from alight-analytics/jf/applying-backoff-for-maven
Applying changes to master
2 parents 3d12faf + 9ce4523 commit 338918b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

setup.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
if sys.version_info[0] >= 3:
2727
# Python 3
2828
from urllib.request import urlopen
29+
from urllib.error import HTTPError
2930
else:
3031
# Python 2
3132
from urllib2 import urlopen
33+
from urllib2 import HTTPError
3234

3335
#
3436
# This script modifies the basic setuptools by adding some functionality to the standard
@@ -52,7 +54,7 @@
5254

5355
PACKAGE_NAME = 'amazon_kclpy'
5456
JAR_DIRECTORY = os.path.join(PACKAGE_NAME, 'jars')
55-
PACKAGE_VERSION = '2.0.2'
57+
PACKAGE_VERSION = '2.0.5'
5658
PYTHON_REQUIREMENTS = [
5759
'boto',
5860
# argparse is part of python2.7 but must be declared for python2.6
@@ -182,7 +184,6 @@ def download_file(self, url, dest):
182184
"""
183185
Downloads a file at the url to the destination.
184186
"""
185-
print('Attempting to retrieve remote jar {url}'.format(url=url))
186187
try:
187188
response = self.make_request_with_backoff(url)
188189

@@ -204,11 +205,14 @@ def download_files(self):
204205

205206
def make_request_with_backoff(self, url):
206207
for attempt_number in range(MAX_URL_DOWNLOAD_ATTEMPTS):
207-
response = urlopen(url)
208-
if response.getcode() == 429:
209-
sleep_time = 2 ** attempt_number
210-
print('"429 Too Many Requests" response received. Sleeping {} seconds and trying again.'.format(sleep_time))
211-
sleep(sleep_time)
208+
print('Attempting to retrieve remote jar {url}'.format(url=url))
209+
try:
210+
return urlopen(url)
211+
except HTTPError as e:
212+
if e.code == 429:
213+
sleep_time = 2 ** attempt_number
214+
print('"429 Too Many Requests" response received. Sleeping {} seconds and trying again.'.format(sleep_time))
215+
sleep(sleep_time)
212216
else:
213217
return response
214218
raise Exception('"429 Too Many Requests" responses received.')

0 commit comments

Comments
 (0)