2017-02-23 58 views
0

我试图put一个项目为亚马逊DynamoDB表使用python脚本,但是当我运行python脚本我得到以下错误:如何使用python将项目放入DynamoDB表中?

Traceback (most recent call last): 
    File "./table.py", line 32, in <module> 
    item.put(None, None) 
    File "/usr/local/lib/python2.7/dist-packages/boto/dynamodb/item.py", line 183, in put 
    return self.table.layer2.put_item(self, expected_value, return_values) 
    File "/usr/local/lib/python2.7/dist-packages/boto/dynamodb/layer2.py", line 551, in put_item 
    object_hook=self.dynamizer.decode) 
    File "/usr/local/lib/python2.7/dist-packages/boto/dynamodb/layer1.py", line 384, in put_item 
    object_hook=object_hook) 
    File "/usr/local/lib/python2.7/dist-packages/boto/dynamodb/layer1.py", line 119, in make_request 
    retry_handler=self._retry_handler) 
    File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 954, in _mexe 
    status = retry_handler(response, i, next_sleep) 
    File "/usr/local/lib/python2.7/dist-packages/boto/dynamodb/layer1.py", line 159, in _retry_handler 
    data) 
boto.exception.DynamoDBResponseError: DynamoDBResponseError: 400 Bad Request 
{u'message': u'Requested resource not found', u'__type': u'com.amazonaws.dynamodb.v20111205#ResourceNotFoundException'} 

我的代码是:

#!/usr/bin/python 

import boto 
import boto.s3 
import sys 

from boto import dynamodb2 
from boto.dynamodb2.table import Table 
from boto.s3.key import Key 
import boto.dynamodb 

conn = boto.dynamodb.connect_to_region('us-west-2', aws_access_key_id=<My_access_key>, aws_secret_access_key=<my_secret_key>) 

entity = conn.create_schema(hash_key_name='RPI_ID', hash_key_proto_value=str, range_key_name='PIC_ID', range_key_proto_value=str) 
table = conn.create_table(name='tblSensor', schema=entity, read_units=10, write_units=10) 


item_data = { 
     'Pic_id': 'P100', 
     'RId': 'R100', 
     'Temperature': '28.50' 
    } 
item = table.new_item(
     # Our hash key is 'forum' 
     hash_key='RPI_ID', 
     # Our range key is 'subject' 
     range_key='PIC_ID', 
     # This has the 
     attrs=item_data 
    ) 

item.put() // I got error here. 

我参考的是:Setting/Getting/Deleting CORS Configuration on a Bucket

+0

你检查表是否创建好吗? –

+0

@Nihal Sharma是的,表已成功创建。 – rsp

+0

你确定桌子在'us-west-2'吗? –

回答

0

我搜索谷歌和解决我这个问题。我已经在我的覆盆子pi板上设置了正确的时间日期并运行该程序,它工作正常。

0

我跑你的代码在我的帐户和它的工作100%完美,返回:

{u'ConsumedCapacityUnits': 1.0} 

你可能要检查你使用的是最新版本的boto

pip install boto --upgrade 
相关问题