本文整理汇总了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))
示例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)
示例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
示例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'))
示例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
示例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))