Skip to content

Commit

Permalink
#48 Fix exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrossard committed May 5, 2017
1 parent d1e0913 commit 8f014f6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions s3iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,12 @@ def get_role(self):
"/latest/meta-data/iam/security-credentials/"
))

response = None
try:
response = urllib2.urlopen(request)
self.iamrole = (response.read())
except Exception:
response = None
self.iamrole = ""
finally:
if response:
response.close()
Expand All @@ -242,13 +244,14 @@ def get_credentials(self):
"latest/meta-data/iam/security-credentials/",
), self.iamrole))

response = None
try:
response = urllib2.urlopen(request)
data = json.loads(response.read())
self.access_key = data['AccessKeyId']
self.secret_key = data['SecretAccessKey']
self.token = data['Token']
except Exception:
response = None
finally:
if response:
response.close()
Expand Down

0 comments on commit 8f014f6

Please sign in to comment.