Skip to content

Improve error messages when S3 returns a 403 error during an ls operation #1276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions S3/Exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@ def parse_error_xml(tree):
raise S3ResponseError("Malformed error XML returned from remote server.")
return info

class S3AccessDenied(S3Error):
def __init__(self, resource, response):
super(S3AccessDenied, self).__init__(response)
self.resource = resource
debug("S3AccessDenied: %s (%s): %s" % (self.status, self.reason, self.resource))

def __unicode__(self):
retval = u"%d " % (self.status)
retval += (u"(%s)" % (self.code or self.reason))
error_msg = self.message
if error_msg:
retval += (u": %s" % error_msg)
retval += (u": %s" % (self.resource))
return retval

class CloudFrontError(S3Error):
pass
Expand Down
2 changes: 1 addition & 1 deletion S3/S3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ def _http_403_handler(self, request, response, fn, *args, **kwargs):
self.fallback_to_signature_v2 = True
return fn(*args, **kwargs)

raise S3Error(response)
raise S3AccessDenied(request.resource, response)

def update_region_inner_request(self, request):
"""Get and update region for the request if needed.
Expand Down