2017-02-23 2 views
0

Je suis en train de put un élément dans une table DynamoDB Amazon en utilisant un script python, mais quand je lance le script python je reçois l'erreur suivante:Comment mettre des éléments dans la table DynamoDB en utilisant python?

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'} 

Mon code est:

#!/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. 

ma référence est: Setting/Getting/Deleting CORS Configuration on a Bucket

+0

Avez-vous vérifié si la table a été créée fine ?? –

+0

@Nihal Sharma Oui, la table a été créée avec succès. – rsp

+0

Êtes-vous sûr que la table est dans 'us-west-2'? –

Répondre

0

Je recherche google et résolu mon problème que. J'ai mis temps exact et date sur mon conseil de framboise pi et exécuter ce programme, ça fonctionne bien.

0

J'ai couru votre code dans mon compte et cela a fonctionné à 100% parfait, retour:

{u'ConsumedCapacityUnits': 1.0} 

Vous pouvez vérifier que vous utilisez la dernière version de boto:

pip install boto --upgrade