2016-06-12 82 views
1

我有兩個s3存儲桶,以「srcs3bck」和「dsts3bck」爲例,我在srcs3bck中有一個文本文件。我試着在StackOverFlow question中建議的答案將源複製到目的地。但是當我做我得到404響應錯誤,說明我的源桶不可用。在兩個s3存儲桶之間複製拋出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> 
>>>  

還有什麼我需要改變這一點。我不確定我在做什麼錯誤。任何人都可以幫我解決這個問題。在此先感謝

回答

4

copy_key方法實際上是查找存儲區名稱,而不是存儲桶對象。所以試試這個:

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