Boto的Dynamodb错误:'144095370333333371533171708191171526873`的不精确数字

时间:2014-01-08 02:50:53

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

我正在使用带有boto的Dynamodb2。我的架构定义如下:

schema=[
                HashKey('id', data_type=NUMBER),

       ]

要插入id字段,我使用Python的uuid生成一个随机id,命令为uuid.uuid1(),如下所示:

id = int(uuid.uuid1())

但是当我尝试在表中插入ID时,我收到以下错误:

{
  "error_message": "BotoClientError: Inexact numeric for `144095370333333371533171708191171526873`\nNone",

  "traceback": "Traceback (most recent call last):\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 195, in wrapper\n    response = callback(request, *args, **kwargs)\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 426, in dispatch_list\n    return self.dispatch('list', request, **kwargs)\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 458, in dispatch\n    response = method(request, **kwargs)\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 1320, in post_list\n    updated_bundle = self.obj_create(bundle, **self.remove_api_resource_names(kwargs))\n\n  File \"/home/sudip/phunka/projects/freelance/2youtubestats/ViewsApp/myapi.py\", line 186, in obj_create\n    returned_id = form.save()\n\n  File \"/home/sudip/phunka/projects/freelance/2youtubestats/ViewsApp/forms.py\", line 88, in save\n    save_single_video(final_data)\n\n  File \"/home/sudip/phunka/projects/freelance/2youtubestats/ViewsApp/dynamo_operations.py\", line 141, in save_single_video\n    main_table.put_item(data=data)\n\n  File \"/usr/local/lib/python2.7/dist-packages/boto/dynamodb2/table.py\", line 491, in put_item\n    return item.save(overwrite=overwrite)\n\n  File \"/usr/local/lib/python2.7/dist-packages/boto/dynamodb2/items.py\", line 439, in save\n    final_data = self.prepare_full()\n\n  File \"/usr/local/lib/python2.7/dist-packages/boto/dynamodb2/items.py\", line 320, in prepare_full\n    final_data[key] = self._dynamizer.encode(value)\n\n  File \"/usr/local/lib/python2.7/dist-packages/boto/dynamodb/types.py\", line 234, in encode\n    return {dynamodb_type: encoder(attr)}\n\n  File \"/usr/local/lib/python2.7/dist-packages/boto/dynamodb/types.py\", line 250, in _encode_n\n    raise DynamoDBNumberError(msg)\n\nDynamoDBNumberError: BotoClientError: Inexact numeric for `144095370333333371533171708191171526873`\nNone\n"
}

我错过了什么吗?

1 个答案:

答案 0 :(得分:2)

DynamoDB中的数字最多可包含38位数字(AWS docs)。

id = int(uuid.uuid1()/4)

这应该为您提供DynamoDB将保留的随机ID。