我正在尝试使用boto for python从Amazon S3获取数据。
from boto.s3.connection import S3Connection
AWS_KEY = 'MY_KEY'
AWS_SECRET = 'MY_SECRET'
aws_connection = S3Connection(AWS_KEY, AWS_SECRET)
bucket = aws_connection.get_bucket('s3://mybucket.buckets.com/')
for file_key in bucket.list():
print file_key.name
我正在传递有效的Key,secret_key和Bucketname。
当我尝试执行上面的代码时,我收到以下错误 -
Traceback (most recent call last):
File "MyPython_Script.py", line 7, in <module>
bucket = aws_connection.get_bucket('s3://mybucket.buckets.com/')
File "/usr/local/lib/python2.7/site-packages/boto/s3/connection.py", line 506, in get_bucket
return self.head_bucket(bucket_name, headers=headers)
File "/usr/local/lib/python2.7/site-packages/boto/s3/connection.py", line 525, in head_bucket
response = self.make_request('HEAD', bucket_name, headers=headers)
File "/usr/local/lib/python2.7/site-packages/boto/s3/connection.py", line 668, in make_request
retry_handler=retry_handler
File "/usr/local/lib/python2.7/site-packages/boto/connection.py", line 1071, in make_request
retry_handler=retry_handler)
File "/usr/local/lib/python2.7/site-packages/boto/connection.py", line 1030, in _mexe
raise ex
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
知道如何克服这个错误吗?我的格式是否用于正确传递存储桶名称?
答案 0 :(得分:2)
您只需要传递桶的名称,而不是无缝的URL(请注意,s3端点将是http://s3-aws-region.amazonaws.com/bucket)
如果你正在使用boto2
from boto.s3.connection import S3Connection
AWS_KEY = 'MY_KEY'
AWS_SECRET = 'MY_SECRET'
aws_connection = S3Connection(AWS_KEY, AWS_SECRET)
bucket = aws_connection.get_bucket('bucket_name', validate=False)
for file_key in bucket.list():
print file_key.name
如果你正在使用boto3
import boto3
s3 = boto3.resource('s3')
bucket = s3.Bucket('name')