在两个 S3 存储桶之间复制会引发 404 错误



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

但我试图得到水桶并得到所有的kes。它正在显示密钥。

>>> 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)

最新更新