【问题标题】:Boto DynamoDB not supporting dictionaries?Boto DynamoDB 不支持字典?
【发布时间】:2015-11-29 06:13:26
【问题描述】:

我有以下 Python 代码尝试将项目存储到 DynamoDB 中。虽然一切都适用于字符串等。当我尝试添加字典时它失败了。

该表有一个称为“参数”的主哈希键

import boto
from boto.dynamodb import connect_to_region

conn = connect_to_region('eu-west-1')

table = conn.get_table('my-table')

item_dict = {
    'Parameter': 'dbparams',
    'Value': {
        'host': 'myserver',
        'user': 'myusername',
        'password': 'mypass',
        'port': '5555',
    },
}

item = table.new_item(attrs=item_dict)
item.put()

这会导致以下错误:

boto.dynamodb.exceptions.DynamoDBValidationError: DynamoDBValidationError: 400 Bad Request
{'__type': 'com.amazon.coral.validate#ValidationException', 'message': 'Supplied AttributeValue is empty, must contain exactly one of the supported datatypes'}

这样做的正确方法是什么?我在 Boto 文档中也找不到示例。

【问题讨论】:

    标签: python amazon-dynamodb boto


    【解决方案1】:

    我能够使用 boto + dynamodb2 库执行代码。您似乎在 'port': '5555' 之后有一个 extra 逗号 - 你可以摆脱它。我附上了结果的屏幕截图 - 所以你可以看到我得到了什么。希望这会有所帮助。如果您想使用库http://boto.cloudhackers.com/en/latest/dynamodb2_tut.html,这是一个链接。

    import boto.dynamodb2
    from boto.dynamodb2.table import Table
    
    #Put in your connection code here and get access to the connection and table objects.
    #Once you have your table object..... execute put
    
    table.put_item(data={'Id': 323,
    'Parameter': 'dbparams',
    'Value': {
            'host': 'myserver',
            'user': 'myusername',
            'password': 'mypass',
            'port': '5555'
        }
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-07
      • 1970-01-01
      相关资源
      最近更新 更多