Python Boto3-禁用自动多部分上载
我使用的是一个S3兼容的后端,它不支持多端口加载 我有一个疏远的情况,在一些服务器上,当我上传一个文件时,它会正常完成,但在其他服务器上,bot3会自动尝试使用多端口上传文件。我试图上传的文件与测试目的的文件完全相同,都是相同的后端、区域/租户、bucket等 如图所示,多端口负载在需要时自动启用:Python Boto3-禁用自动多部分上载,python,python-2.7,amazon-s3,boto3,Python,Python 2.7,Amazon S3,Boto3,我使用的是一个S3兼容的后端,它不支持多端口加载 我有一个疏远的情况,在一些服务器上,当我上传一个文件时,它会正常完成,但在其他服务器上,bot3会自动尝试使用多端口上传文件。我试图上传的文件与测试目的的文件完全相同,都是相同的后端、区域/租户、bucket等 如图所示,多端口负载在需要时自动启用: 当文件超过特定大小阈值时自动切换到多部分传输 以下是自动切换到多端口负载时的一些日志: DEBUG:botocore.hooks:Event request-created.s3.CreateM
- 当文件超过特定大小阈值时自动切换到多部分传输
DEBUG:botocore.hooks:Event request-created.s3.CreateMultipartUpload: calling handler <function enable_upload_callbacks at 0x2b001b8>
DEBUG:botocore.endpoint:Sending http request: <PreparedRequest [POST]>
INFO:botocore.vendored.requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): mytenant.mys3backend.cloud.corp
DEBUG:botocore.vendored.requests.packages.urllib3.connectionpool:"POST /cassandra/samplefile.tgz?uploads HTTP/1.1" 501 None
DEBUG:botocore.parsers:Response headers: {'date': 'Fri, 18 Dec 2015 09:12:48 GMT', 'transfer-encoding': 'chunked', 'content-type': 'application/xml;charset=UTF-8', 'server': 'HCP V7.2.0.26'}
DEBUG:botocore.parsers:Response body:
<?xml version='1.0' encoding='UTF-8'?>
<Error>
<Code>NotImplemented</Code>
<Message>The request requires functionality that is not implemented in the current release</Message>
<RequestId>1450429968948</RequestId>
<HostId>aGRpLmJvc3RoY3AuY2xvdWQuY29ycDoyNg==</HostId>
</Error>
DEBUG:botocore.hooks:Event needs-retry.s3.CreateMultipartUpload: calling handler <botocore.retryhandler.RetryHandler object at 0x2a490d0>
自动切换到多端口负载时的日志:
DEBUG:botocore.hooks:Event request-created.s3.CreateMultipartUpload: calling handler <function enable_upload_callbacks at 0x2b001b8>
DEBUG:botocore.endpoint:Sending http request: <PreparedRequest [POST]>
INFO:botocore.vendored.requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): mytenant.mys3backend.cloud.corp
DEBUG:botocore.vendored.requests.packages.urllib3.connectionpool:"POST /cassandra/samplefile.tgz?uploads HTTP/1.1" 501 None
DEBUG:botocore.parsers:Response headers: {'date': 'Fri, 18 Dec 2015 09:12:48 GMT', 'transfer-encoding': 'chunked', 'content-type': 'application/xml;charset=UTF-8', 'server': 'HCP V7.2.0.26'}
DEBUG:botocore.parsers:Response body:
<?xml version='1.0' encoding='UTF-8'?>
<Error>
<Code>NotImplemented</Code>
<Message>The request requires functionality that is not implemented in the current release</Message>
<RequestId>1450429968948</RequestId>
<HostId>aGRpLmJvc3RoY3AuY2xvdWQuY29ycDoyNg==</HostId>
</Error>
DEBUG:botocore.hooks:Event needs-retry.s3.CreateMultipartUpload: calling handler <botocore.retryhandler.RetryHandler object at 0x2a490d0>
未从其他服务器切换到多部分但用于同一文件的日志:
DEBUG:botocore.hooks:Event request-created.s3.PutObject: calling handler <function enable_upload_callbacks at 0x7f436c025500>
DEBUG:botocore.endpoint:Sending http request: <PreparedRequest [PUT]>
INFO:botocore.vendored.requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): mytenant.mys3backend.cloud.corp
DEBUG:botocore.awsrequest:Waiting for 100 Continue response.
DEBUG:botocore.awsrequest:100 Continue response seen, now sending request body.
DEBUG:botocore.vendored.requests.packages.urllib3.connectionpool:"PUT /cassandra/samplefile.tgz HTTP/1.1" 200 0
DEBUG:botocore.parsers:Response headers: {'date': 'Fri, 18 Dec 2015 10:05:25 GMT', 'content-length': '0', 'etag': '"b407e71de028fe62fd9f2f799e606855"', 'server': 'HCP V7.2.0.26'}
DEBUG:botocore.parsers:Response body:
DEBUG:botocore.hooks:Event needs-retry.s3.PutObject: calling handler <botocore.retryhandler.RetryHandler object at 0x7f436be1ecd0>
DEBUG:botocore.retryhandler:No retry needed.
问题是:
- 为了避免自动切换到多部分上载,如何 我默认禁用多端口加载还是增加阈值李>
- 一台服务器使用自动多部分,而其他服务器不使用同一文件,这有什么原因吗
connection = boto3.client(service_name='s3',
region_name='',
api_version=None,
use_ssl=True,
verify=True,
endpoint_url=url,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
aws_session_token=None,
config=None)
connection.upload_file('/tmp/samplefile.tgz','mybucket','remotefile.tgz')
myconfig = TransferConfig(
multipart_threshold=9999999999999999, # workaround for 'disable' auto multipart upload
max_concurrency=10,
num_download_attempts=10,
)
connection = boto3.client(service_name='s3',
region_name='',
api_version=None,
use_ssl=True,
verify=True,
endpoint_url=url,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
aws_session_token=None,
config=None)
transfer=S3Transfer(connection,myconfig)
transfer.upload_file('/tmp/samplefile.tgz','mybucket','remotefile.tgz')
我希望这对某人有所帮助我找到了一个解决方法,使用S3Transfer和Transferconfig增加阈值大小,如下所示:
connection = boto3.client(service_name='s3',
region_name='',
api_version=None,
use_ssl=True,
verify=True,
endpoint_url=url,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
aws_session_token=None,
config=None)
connection.upload_file('/tmp/samplefile.tgz','mybucket','remotefile.tgz')
myconfig = TransferConfig(
multipart_threshold=9999999999999999, # workaround for 'disable' auto multipart upload
max_concurrency=10,
num_download_attempts=10,
)
connection = boto3.client(service_name='s3',
region_name='',
api_version=None,
use_ssl=True,
verify=True,
endpoint_url=url,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
aws_session_token=None,
config=None)
transfer=S3Transfer(connection,myconfig)
transfer.upload_file('/tmp/samplefile.tgz','mybucket','remotefile.tgz')
我希望这对我在看boto3的时候遇到你的问题的人有所帮助 当文件超过一个路径时自动切换到多部分传输 特定大小阈值 Yes upload_文件(来自客户端/资源/S3Transfer)将自动转换为多部分上载,默认阈值大小为8 MB 如果您不想使用多部分,那么永远不要使用upload\u file方法,只需使用put\u object方法,它将不会使用多部分 client=boto3.client('s3')
client.put_object(Body=open('/test.csv')、Bucket='mybucket',Key='test.csv')当我查看bot3时,遇到了你的问题 当文件超过一个路径时自动切换到多部分传输 特定大小阈值 Yes upload_文件(来自客户端/资源/S3Transfer)将自动转换为多部分上载,默认阈值大小为8 MB 如果您不想使用多部分,那么永远不要使用upload\u file方法,只需使用put\u object方法,它将不会使用多部分 client=boto3.client('s3')
client.put_object(Body=open('/test.csv')、Bucket='mybucket',Key='test.csv')Hi@RuBiCK您在上述代码中尝试过使用回调函数吗?当我用上面的代码尝试Callbacl时,它给出了一个错误类型error:upload_file()得到了一个意外的关键字参数'Callback',但当我在不使用TransferConfig()的情况下尝试时,它可以工作。。有什么想法吗?我没有测试回调,sorryHi@RuBiCK你在上面的代码中试过使用回调函数吗?当我用上面的代码尝试Callbacl时,它给出了一个错误类型error:upload_file()得到了一个意外的关键字参数'Callback',但当我在不使用TransferConfig()的情况下尝试时,它可以工作。。有什么想法吗?对不起,我没有测试回拨