MCPcopy Create free account
hub / github.com/s3tools/s3cmd / _http_400_handler

Method _http_400_handler

S3/S3.py:1608–1648  ·  view source on GitHub ↗

Returns None if no handler available for the specific error code

(self, request, response, fn, *args, **kwargs)

Source from the content-addressed store, hash-verified

1606 raise S3Error(response)
1607
1608 def _http_400_handler(self, request, response, fn, *args, **kwargs):
1609 """
1610 Returns None if no handler available for the specific error code
1611 """
1612 # AWS response AuthorizationHeaderMalformed means we sent the request to the wrong region
1613 # get the right region out of the response and send it there.
1614 if 'data' in response and len(response['data']) > 0:
1615 failureCode = getTextFromXml(response['data'], 'Code')
1616 if failureCode == 'AuthorizationHeaderMalformed':
1617 # we sent the request to the wrong region
1618 region = getTextFromXml(response['data'], 'Region')
1619 if region is not None:
1620 S3Request.region_map[request.resource['bucket']] = region
1621 info('Forwarding request to %s', region)
1622 return fn(*args, **kwargs)
1623 else:
1624 warning(u'Could not determine bucket the location. Please consider using the --region parameter.')
1625
1626 elif failureCode == 'InvalidRequest':
1627 message = getTextFromXml(response['data'], 'Message')
1628 if message == 'The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.':
1629 debug(u'Endpoint requires signature v4')
1630 self.endpoint_requires_signature_v4 = True
1631 return fn(*args, **kwargs)
1632
1633 elif failureCode == 'InvalidArgument':
1634 # returned by DreamObjects on send_request and send_file,
1635 # which doesn't support signature v4. Retry with signature v2
1636 if not request.use_signature_v2() and not self.fallback_to_signature_v2: # have not tried with v2 yet
1637 debug(u'Falling back to signature v2')
1638 self.fallback_to_signature_v2 = True
1639 return fn(*args, **kwargs)
1640 else:
1641 # returned by DreamObjects on recv_file, which doesn't support signature v4. Retry with signature v2
1642 if not request.use_signature_v2() and not self.fallback_to_signature_v2:
1643 # have not tried with v2 yet
1644 debug(u'Falling back to signature v2')
1645 self.fallback_to_signature_v2 = True
1646 return fn(*args, **kwargs)
1647
1648 return None
1649
1650 def _http_403_handler(self, request, response, fn, *args, **kwargs):
1651 if 'data' in response and len(response['data']) > 0:

Callers 3

send_requestMethod · 0.95
send_fileMethod · 0.95
recv_fileMethod · 0.95

Calls 2

getTextFromXmlFunction · 0.85
use_signature_v2Method · 0.80

Tested by

no test coverage detected