我想使用带有python 3.4和Django的boto 2.38从s3上传文件。
两次首次重试不起作用,但最后一次正常工作(对于重试,它不会自动手动执行。)
我收到此错误:
File "/usr/local/lib/python3.4/dist-packages/boto/s3/key.py", line 750, in send_file
chunked_transfer=chunked_transfer, size=size)
File "/usr/local/lib/python3.4/dist-packages/boto/s3/key.py", line 951, in _send_file_internal
query_args=query_args
File "/usr/local/lib/python3.4/dist-packages/boto/s3/connection.py", line 664, in make_request
retry_handler=retry_handler
File "/usr/local/lib/python3.4/dist-packages/boto/connection.py", line 1071, in make_request
retry_handler=retry_handler)
File "/usr/local/lib/python3.4/dist-packages/boto/connection.py", line 1030, in _mexe
raise ex
File "/usr/local/lib/python3.4/dist-packages/boto/connection.py", line 940, in _mexe
request.body, request.headers)
File "/usr/local/lib/python3.4/dist-packages/boto/s3/key.py", line 844, in sender
http_conn.send(chunk)
File "/usr/lib/python3.4/http/client.py", line 888, in send
self.sock.sendall(data)
BrokenPipeError: [Errno 32] Broken pipe
在日志中,我有正确的主机名。通过在网上搜索我发现我必须提供连接到s3的主机,因为我在很多地区有很多桶,我没有指定主机(或者我应该考虑所有区域的情况?我知道在Boto3中这有一个改进...):
bucket: 'NameOfTheBucket' is in eu-west-1
最大的问题是我无法重现错误,所以如果有人能提供帮助,我将非常感激。
我添加了部分代码:
s3 = connect_s3(
aws_access_key_id=xxxxx,
aws_secret_access_key=xxx,
is_secure=xxxxxx)
self.s3_bucket = s3.lookup(self.s3_bucket_name)
问题在于这部分代码:
def put_s3_file_onepart(self, filename, key_name, headers):
key = self.s3_bucket.new_key(key_name)
key.BufferSize = CHUNK_SIZE
with open(self.abs_path(filename), 'rb') as fp:
key.md5, key.base64md5 = key.compute_md5(fp)
with open(self.abs_path(filename), 'rb') as fp:
key.send_file(fp, headers=headers) <==========
key.close()
在我看来,它与chuncked文件有关。谢谢你的帮助。