Skip to main content
 首页 » 编程设计

python之Amazon S3cmd 在某些大型上传时崩溃

2025年05月04日9mfrbuaa

我经常将大型 bzipped sql 文件上传到 S3,并且最近注意到它因此错误而崩溃。这可能是什么原因造成的?它始终是相同的文件崩溃,但我可以毫无问题地上传更大的文件,所以它似乎没有大小限制。

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
    An unexpected error has occurred. 
  Please report the following lines to: 
  s3tools-general@lists.sourceforge.net 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
 
Traceback (most recent call last): 
  File "/usr/bin/s3cmd", line 1040, in <module> 
    main() 
  File "/usr/bin/s3cmd", line 1020, in main 
    cmd_func(args) 
  File "/usr/bin/s3cmd", line 188, in cmd_object_put 
    response = s3.object_put_uri(real_filename, uri_final, extra_headers) 
  File "/usr/lib/python2.5/site-packages/S3/S3.py", line 195, in object_put_uri 
    return self.object_put(filename, uri.bucket(), uri.object(), extra_headers) 
  File "/usr/lib/python2.5/site-packages/S3/S3.py", line 175, in object_put 
    response = self.send_file(request, file) 
  File "/usr/lib/python2.5/site-packages/S3/S3.py", line 384, in send_file 
    debug("MD5 sums: computed=%s, received=%s" % (md5_computed, response["headers"]["etag"])) 
KeyError: 'etag' 

请您参考如下方法:

S3 没有在其响应中返回 ETag [实体标签]。无论是什么原因导致响应中缺少 ETag,您的 s3cmd 版本都不会期望 ETag 缺失和中止。

据我所知,这在 s3cmd 的最新版本 0.9.9.91 中应该不再是一个问题:

## S3.py ## 
... 
# S3 from time to time doesn't send ETag back in a response :-( 
# Force re-upload here. 
if not response['headers'].has_key('etag'): 
    response['headers']['etag'] = '' 
... 
debug("MD5 sums: computed=%s, received=%s" % (md5_computed, response["headers"]["etag"])) 
... 

确保您使用的是 s3cmd 版本 0.9.9.91。

s3cmd 版本 0.9.9.91 将重试上传。如果此特定文件的后续重试也失败,请更改 S3.py 以打印出完整的 S3 响应,或使用数据包嗅探器 [tcpdump on linux, Wireshark在 Windows 上] 拦截相同的完整 S3 响应。它可能包含有关导致此行为的原因的其他提示。