为什么boto找不到配置文件(凭据)

时间:2014-11-26 12:12:08

标签: python-2.7 unix amazon-web-services amazon-ec2 boto

我创建了新的配置文件:

$ sudo vi ~/.boto

我粘贴我的凭据(如用于botp的readthedocs中所写):

[Credentials]
aws_access_key_id = YOURACCESSKEY
aws_secret_access_key = YOURSECRETKEY

我试图检查连接:

import boto

boto.set_stream_logger('boto')
s3 = boto.connect_s3("us-east-1")

和我的回答:

2014-11-26 14:05:49,532 boto [DEBUG]:Using access key provided by client.
2014-11-26 14:05:49,532 boto [DEBUG]:Retrieving credentials from metadata server.
2014-11-26 14:05:50,539 boto [ERROR]:Caught exception reading instance data
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/boto/utils.py", line 210, in retry_url
    r = opener.open(req, timeout=timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 422, in _open
    '_open', req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1214, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1184, in do_open
    raise URLError(err)
URLError: <urlopen error timed out>
2014-11-26 14:05:50,540 boto [ERROR]:Unable to read instance data, giving up
Traceback (most recent call last):
  File "/Users/user/PycharmProjects/project/untitled.py", line 8, in <module>
    s3 = boto.connect_s3("us-east-1")
  File "/Library/Python/2.7/site-packages/boto/__init__.py", line 141, in connect_s3
    return S3Connection(aws_access_key_id, aws_secret_access_key, **kwargs)
  File "/Library/Python/2.7/site-packages/boto/s3/connection.py", line 190, in __init__
    validate_certs=validate_certs, profile_name=profile_name)
  File "/Library/Python/2.7/site-packages/boto/connection.py", line 569, in __init__
    host, config, self.provider, self._required_auth_capability())
  File "/Library/Python/2.7/site-packages/boto/auth.py", line 975, in get_auth_handler
    'Check your credentials' % (len(names), str(names)))
boto.exception.NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV1Handler'] Check your credentials

为什么没找到凭据? 有什么我做错了吗?

1 个答案:

答案 0 :(得分:0)

您的问题是: 您提供的字符串'us-west-1'将作为第一个参数被视为AWSAccessKeyID。

你想要的是:

首先创建连接,请注意连接中没有区域或位置信息。

conn = boto.connect_s3('your_access_key', 'your_secret_key')

然后当你想用桶做一些事情时,把区域信息写成一个参数。

from boto.s3.connection import Location
conn.create_bucket('mybucket', location=Location.USWest)

或:

conn.create_bucket('mybucket', location='us-west-1')
  

默认情况下,该位置是空字符串,它被解释为美国经典区域,即原始S3区域。但是,通过在创建存储桶时指定其他位置,您可以指示S3在该位置创建存储桶。