问题描述
我正在尝试使用 https:/提供的访问密钥ID和秘密访问密钥从s3存储桶下载文件./db.humanconnectome.org .但是,即使我能够导航数据库并找到文件(如通过aws cli配置我的凭据),尝试下载它们也会导致以下错误:"botocore.exceptions.ClientError:调用HeadObject操作时发生错误(403):禁止"
I am trying to download files from a s3 bucket by using the Access Key ID and Secret Access Key provided by https://db.humanconnectome.org. However, even though I am able to navigate the database and find the files (as I have configured my credentials via aws cli), attempting to download them results in the following error:"botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden"
使用相同的凭据,我可以浏览相同的数据库并通过诸如Cyberduck之类的云存储浏览器手动下载文件,因此Cyberduck如何访问数据不会调用403 Forbidden错误.
With the same credentials, I can browse the same database and download the files manually via a cloud storage browser such as Cyberduck, so how Cyberduck accesses the data does not invoke a 403 Forbidden error.
我还验证了boto3能够访问我的AWS凭证,并且还通过对它们进行硬编码来尝试.
I have also verified that boto3 is able to access my aws credentials, and also tried by hardcoding them.
我如何尝试下载数据非常简单,并复制了boto3 docs示例: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-example-download-file.html
How I am attempting to download the data is very straightforward, and replicates the boto3 docs example: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-example-download-file.html
s3 = boto3.client('s3',
aws_access_key_id=ACCESS_KEY_ID,
aws_secret_access_key=ACCESS_KEY,)
s3.download_file(Bucket=BUCKET_NAME, Key=FILE_KEY, Filename=FILE_NAME)
这应将文件下载到FILE_NAME给出的位置和文件,但会调用403 Forbidden错误.
This should download the file to the location and file given by FILE_NAME, but instead invokes the 403 Forbidden error.
推荐答案
下载文件时,您还需要传递存储区.尝试使用CLI配置region
或在创建客户端时通过region_name
.
You'll need to pass the bucket region as well when downloading the file. Try configuring region
using the CLI or pass region_name
when creating the client.
s3 = boto3.client('s3',
aws_access_key_id=ACCESS_KEY_ID,
aws_secret_access_key=ACCESS_KEY,
region_name=AWS_REGION)
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html
这篇关于从带有boto3的AWS S3存储桶下载文件导致ClientError:发生错误(403):禁止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!