bash 发现 Boto 异常 NoAuthHandler
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24832524/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Boto Exception NoAuthHandler Found
提问by Tai
I'm getting the following error:
我收到以下错误:
File "/Users/tai/Desktop/FlashY/flashy/sniffer/database.py", line 21, in <module>
import dynamoStorage
File "/Users/tai/Desktop/FlashY/flashy/sniffer/dynamoStorage.py", line 37, in <module>
swfTable = Table(decompiled_dynamo_table, connection=dynamoConn)
File "/Library/Python/2.7/site-packages/boto/dynamodb2/table.py", line 107, in __init__
self.connection = DynamoDBConnection()
File "/Library/Python/2.7/site-packages/boto/dynamodb2/layer1.py", line 183, in __init__
super(DynamoDBConnection, self).__init__(**kwargs)
File "/Library/Python/2.7/site-packages/boto/connection.py", line 1073, in __init__
profile_name=profile_name)
File "/Library/Python/2.7/site-packages/boto/connection.py", line 572, in __init__
host, config, self.provider, self._required_auth_capability())
File "/Library/Python/2.7/site-packages/boto/auth.py", line 883, in get_auth_handler
'Check your credentials' % (len(names), str(names)))
boto.exception.NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV4Handler'] Check your credentials
When I had the auth directly in the file my keys worked so I know the keys are correct.
当我直接在文件中进行身份验证时,我的密钥起作用了,所以我知道密钥是正确的。
I have for awsAccess.py:
我有 awsAccess.py:
#aswAccess holds the names of the bash environment set keys.
#used by other classes to create a connection to aws
aws_access_key_id=os.getenv('AWS_ACCESS_KEY');
aws_secret_access_key=os.getenv('AWS_SECRET_KEY');
aws_dynamo_region=os.getenv('DYANAMO_REGION')
and I have for database.py
我有 database.py
#for connecting to aws
aws_access_key_id=awsAccess.aws_access_key_id
aws_secret_access_key=awsAccess.aws_secret_access_key
aws_dynamo_region=awsAccess.aws_dynamo_region
aws_dynamo_table="decompiled_swf_text"
conn= S3Connection(aws_access_key_id,aws_secret_access_key);
dynamoConn = boto.connect_dynamodb(aws_access_key_id, aws_secret_access_key)
dTable = dynamoConn.get_table(aws_dynamo_table)
So I know the keys themselves are correct.
所以我知道密钥本身是正确的。
I have a .bash_profile file that looks like this (**indicating removed, also I tried with and without ""'s):
我有一个 .bash_profile 文件,看起来像这样(**表示已删除,我也尝试过使用和不使用“”):
export AWS_ACCESS_KEY="myAccessKey**"
export AWS_SECRET_KEY="mySecretKey**"
export DYNAMO_REGION="us-east"
I run source ~/.bash_profile, and then tried running but get the error. I can't see why importing would alter the impact of the same key string.
我运行 source ~/.bash_profile,然后尝试运行但出现错误。我不明白为什么导入会改变相同密钥字符串的影响。
回答by Jan Vlcinsky
Few tips:
小贴士:
- assert in your code, that the values for ID aws_access_key and aws_secret_access_key are not empty. It is likely, you do not have them set at the place you think you have.
- remove authentication arguments from
boto.connect_<something>
. This will letboto
to use built in authentication handlers and these shall try reading the file, checking environmental variables etc. You will have your code simpler while still being able to provide all what is needed by any ofboto
authentication methods. - my favourit authentication method is to use ini file (usually named
boto.cfg
) and havingBOTO_CONFIG
environmental variable set to full path to this file, e.g. to `"/home/javl/.boto/boto.cfg" - note, that if you pass any of the authentication parameters to
boto.connect_<something>
with valuenull
, it will work asboto
will check other methods to find the value. - since about a year ago, there is an option
profile
, allowing to refer to specific profile in boto config file. This let me switching to different profiles anywhere in the code.
- 在您的代码中声明,ID aws_access_key 和 aws_secret_access_key 的值不为空。很可能,您没有将它们设置在您认为拥有的位置。
- 从
boto.connect_<something>
. 这将允许boto
使用内置的身份验证处理程序,这些处理程序将尝试读取文件、检查环境变量等。您将使代码更简单,同时仍然能够提供任何boto
身份验证方法所需的所有内容。 - 我最喜欢的身份验证方法是使用 ini 文件(通常命名为
boto.cfg
)并将BOTO_CONFIG
环境变量设置为该文件的完整路径,例如“/home/javl/.boto/boto.cfg” - 请注意,如果您将任何身份验证参数传递给
boto.connect_<something>
with valuenull
,它将像boto
检查其他方法以查找该值一样工作。 - 大约一年前,有一个选项
profile
,允许引用 boto 配置文件中的特定配置文件。这让我可以在代码中的任何位置切换到不同的配置文件。
For more tips and details, see related SO answer
有关更多提示和详细信息,请参阅相关 SO 答案