當前位置: 首頁>>代碼示例>>Python>>正文


Python exceptions.S3UploadFailedError方法代碼示例

本文整理匯總了Python中boto3.exceptions.S3UploadFailedError方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.S3UploadFailedError方法的具體用法?Python exceptions.S3UploadFailedError怎麽用?Python exceptions.S3UploadFailedError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在boto3.exceptions的用法示例。


在下文中一共展示了exceptions.S3UploadFailedError方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: upload_file

# 需要導入模塊: from boto3 import exceptions [as 別名]
# 或者: from boto3.exceptions import S3UploadFailedError [as 別名]
def upload_file(self, filename, bucket, key,
                    callback=None, extra_args=None):
        """Upload a file to an S3 object.

        Variants have also been injected into S3 client, Bucket and Object.
        You don't have to use S3Transfer.upload_file() directly.
        """
        if not isinstance(filename, six.string_types):
            raise ValueError('Filename must be a string')

        subscribers = self._get_subscribers(callback)
        future = self._manager.upload(
            filename, bucket, key, extra_args, subscribers)
        try:
            future.result()
        # If a client error was raised, add the backwards compatibility layer
        # that raises a S3UploadFailedError. These specific errors were only
        # ever thrown for upload_parts but now can be thrown for any related
        # client error.
        except ClientError as e:
            raise S3UploadFailedError(
                "Failed to upload %s to %s: %s" % (
                    filename, '/'.join([bucket, key]), e)) 
開發者ID:skarlekar,項目名稱:faces,代碼行數:25,代碼來源:transfer.py

示例2: _s3_upload_file

# 需要導入模塊: from boto3 import exceptions [as 別名]
# 或者: from boto3.exceptions import S3UploadFailedError [as 別名]
def _s3_upload_file(paths, prefix, s3_client, acl):
        local_filename, bucket, s3_path = paths
        retry = 0
        # backoff and retry
        while retry < 5:
            LOG.info(
                f"s3://{bucket}/{prefix + s3_path}", extra={"nametag": PrintMsg.S3}
            )
            try:
                s3_client.upload_file(
                    local_filename, bucket, prefix + s3_path, ExtraArgs={"ACL": acl}
                )
                break
            except Exception as e:  # pylint: disable=broad-except
                retry += 1
                LOG.error("S3 upload error: %s" % e)
                # give up if we've exhausted retries, or if the error is not-retryable
                # ie. AccessDenied
                if retry == 5 or (
                    isinstance(e, S3UploadFailedError) and "(AccessDenied)" in str(e)
                ):
                    raise TaskCatException("Failed to upload to S3")
                time.sleep(retry * 2) 
開發者ID:aws-quickstart,項目名稱:taskcat,代碼行數:25,代碼來源:_s3_sync.py

示例3: test_upload_file_with_s3_upload_failed_error

# 需要導入模塊: from boto3 import exceptions [as 別名]
# 或者: from boto3.exceptions import S3UploadFailedError [as 別名]
def test_upload_file_with_s3_upload_failed_error():
    """Tests Upload file with S3UploadFailedError, which could indicate AWS token expires."""
    upload_file = MagicMock(
        side_effect=S3UploadFailedError(
            "An error occurred (ExpiredToken) when calling the "
            "CreateMultipartUpload operation: The provided token has expired."))
    client = Mock()
    client.Object.return_value = MagicMock(
        metadata=defaultdict(str), upload_file=upload_file)
    initial_parallel = 100
    upload_meta = {
        'no_sleeping_time': True,
        'parallel': initial_parallel,
        'put_callback': None,
        'put_callback_output_stream': None,
        'existing_files': [],
        SHA256_DIGEST: '123456789abcdef',
        'stage_info': {
            'location': 'sfc-teststage/rwyitestacco/users/1234/',
            'locationType': 'S3',
        },
        'client': client,
        'dst_file_name': 'data1.txt.gz',
        'src_file_name': path.join(THIS_DIR, 'data', 'put_get_1.txt'),
        'overwrite': True,
    }
    upload_meta['real_src_file_name'] = upload_meta['src_file_name']
    upload_meta[
        'upload_size'] = os.stat(upload_meta['src_file_name']).st_size

    akey = SnowflakeRemoteStorageUtil.upload_one_file(upload_meta)
    assert akey is None
    assert upload_meta['result_status'] == ResultStatus.RENEW_TOKEN 
開發者ID:snowflakedb,項目名稱:snowflake-connector-python,代碼行數:35,代碼來源:test_unit_s3_util.py

示例4: backup

# 需要導入模塊: from boto3 import exceptions [as 別名]
# 或者: from boto3.exceptions import S3UploadFailedError [as 別名]
def backup(self, file_path, backup_name):
        key = "%s/%s%s" % (self.__bucket_prefix, backup_name, self.KEY_SUFFIX)
        logger.debug(colored('Attempting to upload object to S3', 'white'))
        try:
            s3_object = self.s3.Object(self.__bucket, key).upload_file(file_path, Callback=logger.info(colored('File uploaded to S3 successfully', 'blue')))
        except S3UploadFailedError as e:
            logger.critical(colored("Error uploading file to S3: %s" % e, 'red')) 
開發者ID:artsy,項目名稱:jenkins-backup-s3,代碼行數:9,代碼來源:backup.py

示例5: mock_s3_upload

# 需要導入模塊: from boto3 import exceptions [as 別名]
# 或者: from boto3.exceptions import S3UploadFailedError [as 別名]
def mock_s3_upload(self):
        dst = os.path.join(self.tmp, "dst")

        class MockS3Object(object):
            def __init__(self, bucket, key):
                self.bucket = bucket
                self.key = key

            def upload_file(self, target, **kwargs):
                if self.bucket in BUCKET_WITHOUT_WRITING_PERMISSION:
                    raise exceptions.S3UploadFailedError()
                shutil.copy2(target, dst)

        self.sagemaker_session.boto_session.resource().Object = MockS3Object
        return dst 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:17,代碼來源:test_utils.py

示例6: upload_file

# 需要導入模塊: from boto3 import exceptions [as 別名]
# 或者: from boto3.exceptions import S3UploadFailedError [as 別名]
def upload_file(self, filename, bucket, key,
                    callback=None, extra_args=None):
        """Upload a file to an S3 object.

        Variants have also been injected into S3 client, Bucket and Object.
        You don't have to use S3Transfer.upload_file() directly.

        .. seealso::
            :py:meth:`S3.Client.upload_file`
            :py:meth:`S3.Client.upload_fileobj`
        """
        if not isinstance(filename, six.string_types):
            raise ValueError('Filename must be a string')

        subscribers = self._get_subscribers(callback)
        future = self._manager.upload(
            filename, bucket, key, extra_args, subscribers)
        try:
            future.result()
        # If a client error was raised, add the backwards compatibility layer
        # that raises a S3UploadFailedError. These specific errors were only
        # ever thrown for upload_parts but now can be thrown for any related
        # client error.
        except ClientError as e:
            raise S3UploadFailedError(
                "Failed to upload %s to %s: %s" % (
                    filename, '/'.join([bucket, key]), e)) 
開發者ID:MattTunny,項目名稱:AWS-Transit-Gateway-Demo-MultiAccount,代碼行數:29,代碼來源:transfer.py


注:本文中的boto3.exceptions.S3UploadFailedError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。