diff --git a/boto3/s3/transfer.py b/boto3/s3/transfer.py index 73a3388b46..486e138c62 100644 --- a/boto3/s3/transfer.py +++ b/boto3/s3/transfer.py @@ -379,7 +379,7 @@ def upload_file( "Failed to upload {} to {}: {}".format( filename, '/'.join([bucket, key]), e ) - ) + ) from ClientError def download_file( self, bucket, key, filename, extra_args=None, callback=None diff --git a/docs/source/guide/error-handling.rst b/docs/source/guide/error-handling.rst index bd83d7cc29..bcf40e1f9f 100644 --- a/docs/source/guide/error-handling.rst +++ b/docs/source/guide/error-handling.rst @@ -199,6 +199,17 @@ Using Amazon Kinesis as an example service, you can use Boto3 to catch the excep The Boto3 ``standard`` retry mode will catch throttling errors and exceptions, and will back off and retry them for you. +.. note:: + + The low-level clients for a few AWS services, such as S3, do not return service errors in a ``ClientError`` object. However, the ``ClientError`` may be accessible via the ``__cause__`` attribute of the overlying error: +.. code-block:: python + + except boto3.exceptions.S3UploadFailedError as error: + _clientError = error.__cause__ + if _clientError.response['Error']['Code'] == 'InvalidRequest': + logger.warn(f"There was an error when attempting to upload: {_clientError.response['Error']['Message']}") + + Additionally, you can also access some of the dynamic service-side exceptions from the client’s exception property. Using the previous example, you would need to modify only the ``except`` clause. .. code-block:: python