26
26
if sys .version_info [0 ] >= 3 :
27
27
# Python 3
28
28
from urllib .request import urlopen
29
+ from urllib .error import HTTPError
29
30
else :
30
31
# Python 2
31
32
from urllib2 import urlopen
33
+ from urllib2 import HTTPError
32
34
33
35
#
34
36
# This script modifies the basic setuptools by adding some functionality to the standard
52
54
53
55
PACKAGE_NAME = 'amazon_kclpy'
54
56
JAR_DIRECTORY = os .path .join (PACKAGE_NAME , 'jars' )
55
- PACKAGE_VERSION = '2.0.2 '
57
+ PACKAGE_VERSION = '2.0.5 '
56
58
PYTHON_REQUIREMENTS = [
57
59
'boto' ,
58
60
# argparse is part of python2.7 but must be declared for python2.6
@@ -182,7 +184,6 @@ def download_file(self, url, dest):
182
184
"""
183
185
Downloads a file at the url to the destination.
184
186
"""
185
- print ('Attempting to retrieve remote jar {url}' .format (url = url ))
186
187
try :
187
188
response = self .make_request_with_backoff (url )
188
189
@@ -204,11 +205,14 @@ def download_files(self):
204
205
205
206
def make_request_with_backoff (self , url ):
206
207
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 )
212
216
else :
213
217
return response
214
218
raise Exception ('"429 Too Many Requests" responses received.' )
0 commit comments