Permalink
Browse files

* S3/Exceptions.py, S3/S3.py: Some HTTP_400 exceptions

  are retriable.



git-svn-id: https://s3tools.svn.sourceforge.net/svnroot/s3tools/s3cmd/trunk@406 830e0280-6d2a-0410-9c65-932aecc39d9d
  • Loading branch information...
1 parent 6d87691 commit b0b9791bbf9a918992f044f8c0db536bdb612442 ludvigm committed May 20, 2010
Showing with 23 additions and 1 deletion.
  1. +5 −0 ChangeLog
  2. +8 −1 S3/Exceptions.py
  3. +10 −0 S3/S3.py
View
5 ChangeLog
@@ -1,3 +1,8 @@
+2010-05-20 Michal Ludvig <mludvig@logix.net.nz>
+
+ * S3/Exceptions.py, S3/S3.py: Some HTTP_400 exceptions
+ are retriable.
+
2010-03-19 Michal Ludvig <mludvig@logix.net.nz>
* s3cmd, S3/ACL.py: Print all ACLs for a Grantee
View
9 S3/Exceptions.py
@@ -35,7 +35,11 @@ class S3Error (S3Exception):
def __init__(self, response):
self.status = response["status"]
self.reason = response["reason"]
- self.info = {}
+ self.info = {
+ "Code" : "",
+ "Message" : "",
+ "Resource" : ""
+ }
debug("S3Error: %s (%s)" % (self.status, self.reason))
if response.has_key("headers"):
for header in response["headers"]:
@@ -49,6 +53,9 @@ def __init__(self, response):
if child.text != "":
debug("ErrorXML: " + child.tag + ": " + repr(child.text))
self.info[child.tag] = child.text
+ self.code = self.info["Code"]
+ self.message = self.info["Message"]
+ self.resource = self.info["Resource"]
def __unicode__(self):
retval = u"%d " % (self.status)
View
10 S3/S3.py
@@ -580,8 +580,17 @@ def send_file(self, request, file, labels, throttle = 0, retries = _max_retries)
response['headers']['etag'] = ''
if response["status"] < 200 or response["status"] > 299:
+ try_retry = False
if response["status"] >= 500:
## AWS internal error - retry
+ try_retry = True
+ elif response["status"] >= 400:
+ err = S3Error(response)
+ ## Retriable client error?
+ if err.code in [ 'BadDigest', 'OperationAborted', 'TokenRefreshRequired', 'RequestTimeout' ]:
+ try_retry = True
+
+ if try_retry:
if retries:
warning("Upload failed: %s (%s)" % (resource['uri'], S3Error(response)))
warning("Waiting %d sec..." % self._fail_wait(retries))
@@ -590,6 +599,7 @@ def send_file(self, request, file, labels, throttle = 0, retries = _max_retries)
else:
warning("Too many failures. Giving up on '%s'" % (file.name))
raise S3UploadError
+
## Non-recoverable error
raise S3Error(response)

0 comments on commit b0b9791

Please sign in to comment.