我正在尝试从我的 Amazon s3 存储桶之一下载文件到 Ubuntu EC2 实例。我在 2 个不同区域创建了两个存储桶,我可以从一个区域的存储桶访问和下载文件,但是当我尝试访问时另一个面临着问题。
Here is the error,
Traceback (most recent call last):
File "listbucket.py", line 7, in <module>
bucket = conn.get_bucket('train-faces')
File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 509, in get_bucket
return self.head_bucket(bucket_name, headers=headers)
File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 556, in head_bucket
response.status, response.reason, body)
boto.exception.S3ResponseError: S3ResponseError: 400 Bad Request
但是我可以从另一个区域的存储桶中下载文件。
最佳答案
您可以在连接 Amazon S3 时指定区域。
波托
import boto
conn = boto.s3.connect_to_region('ap-southeast-2')
conn.get_bucket('train-faces')
boto3
这几天,建议您使用boto3 :
import boto3
s3 = boto3.resource('s3', region_name = 'ap-southeast-2')
bucket = s3.Bucket('train-faces')
或
import boto3
client = boto3.client('s3', region_name = 'ap-southeast-2')
关于python - aws s3下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46031337/