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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:54:49  来源:igfitidea点击:

Boto Exception NoAuthHandler Found

pythonbashpython-2.7amazon-web-services

提问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 let bototo 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 of botoauthentication methods.
  • my favourit authentication method is to use ini file (usually named boto.cfg) and having BOTO_CONFIGenvironmental 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 value null, it will work as botowill 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 value null,它将像boto检查其他方法以查找该值一样工作。
  • 大约一年前,有一个选项profile,允许引用 boto 配置文件中的特定配置文件。这让我可以在代码中的任何位置切换到不同的配置文件。

For more tips and details, see related SO answer

有关更多提示和详细信息,请参阅相关 SO 答案

回答by Tuxlife

I had Problem with Ubuntu Wily (15.10).

我在使用 Ubuntu Wily (15.10) 时遇到了问题。

Here there is an update for ConfigParser.

这里有 ConfigParser 的更新。

.gethas a additional Parameter, but that are not supported with boto.pyami.config.

.get有一个额外的参数,但 boto.pyami.config 不支持。

see hereand here

看到这里这里