botocore.exceptions.NoCredentialsError:无法找到凭据

时间:2016-05-04 10:06:12

标签: python amazon-web-services amazon-dynamodb

我尝试将Amazon AWS DynamoDB与python结合使用。首先,我要通过亚马逊的指南: http://docs.aws.amazon.com/de_de/amazondynamodb/latest/gettingstartedguide/GettingStarted.Python.01.html

然后我运行亚马逊代码我得到错误: botocore.exceptions.NoCredentialsError:无法找到凭据

我拥有的凭据是"〜/ .aws / credentials"它们看起来像这样:

[profile-name]
aws_access_key_id=XXXX
aws_secret_access_key=YYYYYYY

我还尝试设置包含

的condign文件
[profile profile-name]
aws_access_key_id=XXXX
aws_secret_access_key=YYYYYYY

在我的IntelliJ应用程序中,一切都可正常使用此凭据。它刚刚与PyCharm。

我也设置了这个记录器,但这些信息对我没有多大帮助:

boto3.set_stream_logger('botocore', level='DEBUG')

调试信息是:

2016-05-04 11:58:18,162 botocore.credentials [DEBUG] Skipping environment variable credential check because profile name was explicitly set.
2016-05-04 11:58:18,162 botocore.credentials [DEBUG] Looking for credentials via: env
2016-05-04 11:58:18,162 botocore.credentials [DEBUG] Looking for credentials via: assume-role
2016-05-04 11:58:18,162 botocore.credentials [DEBUG] Looking for credentials via: shared-credentials-file
2016-05-04 11:58:18,163 botocore.credentials [DEBUG] Looking for credentials via: config-file
2016-05-04 11:58:18,163 botocore.credentials [DEBUG] Looking for credentials via: ec2-credentials-file
2016-05-04 11:58:18,163 botocore.credentials [DEBUG] Looking for credentials via: boto-config
2016-05-04 11:58:18,163 botocore.credentials [DEBUG] Looking for credentials via: aim-role

最后:我的代码(与教程相同,只是调试器):

from __future__ import print_function # Python 2/3 compatibility
import boto3

boto3.set_stream_logger('botocore', level='DEBUG')

dynamodb = boto3.resource('dynamodb', region_name='eu-central-1',         endpoint_url="http://localhost:8000")


table = dynamodb.create_table(
    TableName='Movies',
    KeySchema=[
        {
            'AttributeName': 'year',
            'KeyType': 'HASH'  #Partition key
        },
       {
            'AttributeName': 'title',
            'KeyType': 'RANGE'  #Sort key
        }
    ],
    AttributeDefinitions=[
        {
            'AttributeName': 'year',
            'AttributeType': 'N'
        },
        {
            'AttributeName': 'title',
            'AttributeType': 'S'
        },

     ],
     ProvisionedThroughput={
        'ReadCapacityUnits': 10,
        'WriteCapacityUnits': 10
    }
)

print("Table status:", table.table_status)

编辑:如果我更改了我的凭据,[profile-name]部分du [default]我收到连接错误。

1 个答案:

答案 0 :(得分:1)

尝试从您的代码中取出endpoint_url。不知道为什么,但为我工作:)