根据Boto3官方文档,我们可以通过传递凭证作为参数来连接S3存储桶。但我面临着问题。
工作场景:硬编码密钥ID&密钥
s3r = boto3.resource('s3', aws_access_key_id='XXXXXXXXXXXXXXXXXXXX',
aws_secret_access_key='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
buck = s3r.Bucket('bucket name')
buck.download_file(filename,filename)
非工作场景:作为参数传递
AccessKey = 'XXXXXXXXXXXXXXXXXXXX'
SecretKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
s3r = boto3.resource('s3', aws_access_key_id=AccessKey, aws_secret_access_key=SecretKey)
buck = s3r.Bucket('bucket name')
buck.download_file(filename,filename)
对于非工作方案,我面临以下错误。
botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden