【问题标题】:python boto error when inserting data to dynamodb将数据插入dynamodb时出现python boto错误
【发布时间】:2016-11-24 01:43:49
【问题描述】:
boto.dynamodb2.exceptions.ValidationException: ValidationException: 400 Bad Request
{'__type': 'com.amazon.coral.validate#ValidationException', 'message': 'One or more parameter values were invalid: Type mismatch for key restoreid expected: S actual: M'}

我有一个带有 id 的简单表格测试

我正在尝试将 id 插入到具有字符串数据类型的表中。主分区键是 id(string)

 table = Table("test")
 stringjson="{\"id\": {\"S\": \"4343\"}}"
 item_data = json.loads(stringjson)

 table.put_item(data=item_data)

我收到上述错误。有什么建议吗?

【问题讨论】:

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


    【解决方案1】:

    我认为你使用了错误的语法

    看http://docs.aws.amazon.com/amazondynamodb/latest/gettingstartedguide/GettingStarted.Python.03.html#GettingStarted.Python.03.01

    您应该尝试以下方法:

    response = table.put_item(
       Item={
            'id': '4343',
        }
    )
    

    【讨论】:

    【解决方案2】:

    DynamoDB 中表的哈希键不能为MAP。您有一个表test 使用哈希键id 作为字符串定义。错误说密钥应该是字符串。此外,无需像这样指定。您可以只为 String 提供双引号中的值。

    {\"S\": \"4343\"}
    

    添加 MAP 数据类型的示例代码:-

    "quid" - 是定义为字符串的表的哈希键

    "info" - 作为 MAP 添加到 DynamoDB 表中

    jsonString = {"quid": "102",  "info": { "plot": "Nothing happens at all.", "rating": "AA"} }
    
    response = table.put_item(
       Item=jsonString
    )
    

    输出:-

    请参考以下截图。 “info”属性已作为 MAP 添加到 DynamoDB 表中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-02
      • 1970-01-01
      • 2021-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多