在两个 s3 存储桶之间复制会抛出 404 错误

copying between two s3 buckets throws 404 error

我有两个 s3 存储桶,取 "srcs3bck" 和 "dsts3bck",我在 srcs3bck 中有一个文本文件。我尝试了 Whosebug question 中建议的答案,将源复制到目标。但是当我这样做时,我收到 404 响应错误,说明我的源存储桶不可用。

但我试图得到桶并获得所有的知识。它正在显示密钥。

>>> import boto
>>> conn=boto.connect(<credentials>)
>>> src = conn.get_bucket("srcs3bck")
>>> src.get_all_keys()
printing my key list properly.
>>> dst = conn.get_bucket("dsts3bck")
>>>
>>> src.get_all_keys()
[<Key: srcs3bck,Test2.txt>]
>>> 
>>> src.list()
<boto.s3.bucketlistresultset.BucketListResultSet object at 0x03768310>
>>> x=src.list()
>>> for i in x: print i
<Key: srcs3bck,Test2.txt>
>>> for i in x: print i.key
Test2.txt
>>> for i in x: dst.copy_key(i.key,src,i.key)
.......
ignoring other lines
....
S3ResponseError: S3ResponseError: 404 Not Found
<Error><Code>NoSuchBucket</Code><Message>The specified bucket does not exist</Message><BucketName>&lt;Bucket: srcs3bck&gt;</BucketName><RequestId>358C4C2420BB91E9</RequestId><HostId>ws6wagGIZqquStqisfGuYHeMMscmmR2Iu8LL4jCv9KpLBzxieiryI/mRwxwz4aQ=</HostId></Error>
>>>     

我还需要更改什么。我不确定我在做什么错误。谁能帮我解决这个问题。提前致谢

copy_key方法实际上是在寻找桶名,而不是桶对象。所以试试这个:

for i in x: dst.copy_key(i.key,src.name,i.key)