S3ResponseError:使用博托403禁止 [英] S3ResponseError: 403 Forbidden using boto
问题描述
我有一个从一个S3帐户的文件复制到另一个S3帐户的脚本,这是工作befoure !!!!这是肯定的。比我今天试了一下,并没有任何更多的它给我的错误 S3ResponseError:403禁止
。我100%肯定的凭据是正确的,我可以从两个帐户manualy使用AWS控制台下载的密钥。
code
高清运行(个体经营):
而真正的:
#删除并从队列中返回一个项目
KEY_NAME = self.q.get()
K =密钥(self.s_bucket,KEY_NAME)
d_key =密钥(self.d_bucket,k.key)
如果不是d_key.exists()或k.etag = d_key.etag!
打印正从{s_bucket} {FILE_NAME}到{d_bucket}。格式(
FILE_NAME = k.key,
s_bucket = source_bucket,
d_bucket = dest_bucket
)
#通过复制另一个现有密钥创建桶中的一个新的关键
ACL = self.s_bucket.get_acl(K)
self.d_bucket.copy_key(d_key.key,self.s_bucket.name,k.key,storage_class = k.storage_class)
d_key.set_acl(ACL)
其他:
打印文件存在
self.q.task_done()
错误:
文件s3_to_s3.py,行88,在运行
self.d_bucket.copy_key(d_key.key,self.s_bucket.name,k.key,storage_class = k.storage_class)
文件/usr/lib/python2.7/dist-packages/boto/s3/bucket.py,线路689,在copy_key
response.reason,体)
S3ResponseError:S3ResponseError:403禁止
&LT;错误&GT;&LT; code取代; AccessDenied&LT; / code&GT;&LT;消息&gt;访问Denied</Message><RequestId>0729E8ADBD7A9E60</RequestId><HostId>PSbbWCLBtLAC9cjW+52X1fUSVErnZeN79/w7rliDgNbLIdCpc9V0bPi8xO9fp1od</HostId></Error>
试试这个:使用博托的重点班,从源头斗复印键到目的地桶
source_key_name ='image.jpg的'#例如
#return重点对象
source_key = source_bucket.get_key(source_key_name)
#使用Key.copy
source_key.copy(destination_bucket,source_key_name)
对于复印功能。你可以设置preserve_acl为真,这将是从源头键复制。
宝途的Key.copy签名:
高清拷贝(个体经营,dst_bucket,dst_key,元数据=无,
reduced_redundancy =假,preserve_acl =假,
encrypt_key =假,validate_dst_bucket = TRUE):
I have a script that copy files from one S3 account to another S3 account, It was working befoure!!!! That's for sure. Than I tried it today and it doesn't any more it gives me error S3ResponseError: 403 Forbidden
. I'm 100% sure credentials are correct and I can go and download keys from both accounts manualy using aws console.
Code
def run(self):
while True:
# Remove and return an item from the queue
key_name = self.q.get()
k = Key(self.s_bucket, key_name)
d_key = Key(self.d_bucket, k.key)
if not d_key.exists() or k.etag != d_key.etag:
print 'Moving {file_name} from {s_bucket} to {d_bucket}'.format(
file_name = k.key,
s_bucket = source_bucket,
d_bucket = dest_bucket
)
# Create a new key in the bucket by copying another existing key
acl = self.s_bucket.get_acl(k)
self.d_bucket.copy_key( d_key.key, self.s_bucket.name, k.key, storage_class=k.storage_class)
d_key.set_acl(acl)
else:
print 'File exist'
self.q.task_done()
Error:
File "s3_to_s3.py", line 88, in run
self.d_bucket.copy_key( d_key.key, self.s_bucket.name, k.key, storage_class=k.storage_class)
File "/usr/lib/python2.7/dist-packages/boto/s3/bucket.py", line 689, in copy_key
response.reason, body)
S3ResponseError: S3ResponseError: 403 Forbidden
<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>0729E8ADBD7A9E60</RequestId><HostId>PSbbWCLBtLAC9cjW+52X1fUSVErnZeN79/w7rliDgNbLIdCpc9V0bPi8xO9fp1od</HostId></Error>
Try this: copy key from source bucket to destination bucket using boto's Key class
source_key_name = 'image.jpg' # for example
#return Key object
source_key = source_bucket.get_key(source_key_name)
#use Key.copy
source_key.copy(destination_bucket,source_key_name)
regarding the copy function. you can set preserve_acl to True and it will be copied from the source key.
Boto's Key.copy signature:
def copy(self, dst_bucket, dst_key, metadata=None,
reduced_redundancy=False, preserve_acl=False,
encrypt_key=False, validate_dst_bucket=True):
这篇关于S3ResponseError:使用博托403禁止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!