【问题标题】:why boto not find config the file (Credentials)为什么boto找不到配置文件(凭据)
【发布时间】:2016-02-08 21:00:51
【问题描述】:

我创建了新的配置文件:

$ sudo vi ~/.boto

我在那里粘贴我的凭据(如 readthedocs for botp 中所写):

[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

为什么找不到凭据? 是不是我做错了什么?

【问题讨论】:

  • 您在编辑配置文件时正在执行sudo。你在运行 python/boto 时是否也在做 sudo?

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


【解决方案1】:

您的问题是: 您作为第一个参数提供的字符串“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 在该位置创建存储桶。

【讨论】:

  • 那么我应该把区域放在哪里?
  • @Cuzi 我刚刚编辑了答案,希望对你有帮助。
猜你喜欢
  • 2011-06-13
  • 2018-03-01
  • 2017-08-21
  • 2012-05-13
  • 2011-12-14
  • 2010-10-12
  • 1970-01-01
  • 1970-01-01
  • 2022-11-29
相关资源
最近更新 更多