put_item包含地图DynamoDB boto3

时间:2017-01-04 14:06:37

标签: python json amazon-dynamodb boto

我有像这样的json

{
  "1555430188927137": {
    "0": {
      "FORM_R_5": {
        "status": 0,
        "rating": null,
        "feedback": null
      },
      "2ABMEDIUM": {
        "status": 0,
        "rating": null,
        "feedback": null
      },
      "FORM_R_9": {
        "status": 0,
        "rating": null,
        "feedback": null
      },
      "title": "b"
    },
    "1": {
      "36ABMEDIUM": {
        "status": 0,
        "rating": null,
        "feedback": null
      },
      "35ABMEDIUM": {
        "status": 0,
        "rating": null,
        "feedback": null
      },
      "38ABEASY": {
        "status": 0,
        "rating": null,
        "feedback": null
      },
      "title": "a"
    }
  }
}

我想把这个json作为一个地图放入我的项目但它似乎不起作用我最终得到这个(缩短)错误消息: “serialize_to_request raise ParamValidationError(report = report.generate_report())botocore.exceptions.ParamValidationError:参数验证失败:参数Item.packs.M.1555430188927137.M(key:0)的类型无效,值:0,类型:,有效类型:参数Item.packs.M.1555430188927137.M(键:1)的无效类型,值:1,类型:,有效类型:“

Python代码

formation_list = {u'1555430188927137': {0: {u'FORM_R_5': {'status': 0, 'rating': None, 'feedback': None}, u'2ABMEDIUM': {'status': 0, 'rating': None, 'feedback': None}, u'FORM_R_9': {'status': 0, 'rating': None, 'feedback': None}, 'title': u'b'}, 1: {u'36ABMEDIUM': {'status': 0, 'rating': None, 'feedback': None}, u'35ABMEDIUM': {'status': 0, 'rating': None, 'feedback': None}, u'38ABEASY': {'status': 0, 'rating': None, 'feedback': None}, 'title': u'a'}}}
dynamodb = boto3.resource('dynamodb', region_name='eu-west-1')
table = dynamodb.Table('MyTable')

table.put_item(
    Item={
        "id" : "test",
        "packs": formation_list
    }
)

如果我这样做,效果很好:

  Item={
        "id" : "test",
        "packs": {
            "pack" : "hello world!"
        }
    }

0 个答案:

没有答案