2012-08-29 75 views
2

我試圖使用掃描功能如下,以從表中檢索任何10個結果在我的數據庫:DynamoDB掃描函數返回正確的結果,但與DynamoDBResponseError

conn = boto.connect_dynamodb(
     aws_access_key_id=config.AWS_KEY, 
     aws_secret_access_key=config.AWS_SECRET) 

    table = conn.get_table('tablename') 
    results = table.scan(attributes_to_get={'id'}, 
      max_results=10) 

    for item in results: 
    print item 

    ./dbtest.py 
    {'id': 'SkAJWDUZPSNrwepf7gdnFhExXPFABmqLjk1ADDRJuoo'} 
    {'id': 'RjAVvd4SAmjtUbXEYmzBaIIDuruL5UZWEQPdcpj4XRc'} 
    ... 

但後來我在得到這個錯誤結束後(返回正確的結果後):

Traceback (most recent call last): 
    File "./mediatest.py", line 23, in <module> 
    for item in results: 
    File "/usr/lib/python2.7/dist-packages/boto/dynamodb/layer2.py", line 767, in scan 
    object_hook=item_object_hook) 
    File "/usr/lib/python2.7/dist-packages/boto/dynamodb/layer1.py", line 521, in scan 
    return self.make_request('Scan', json_input, object_hook=object_hook) 
    File "/usr/lib/python2.7/dist-packages/boto/dynamodb/layer1.py", line 121, in make_request 
    retry_handler=self._retry_handler) 
    File "/usr/lib/python2.7/dist-packages/boto/connection.py", line 746, in _mexe 
    status = retry_handler(response, i, next_sleep) 
    File "/usr/lib/python2.7/dist-packages/boto/dynamodb/layer1.py", line 148, in _retry_handler 
    json_response) 
boto.exception.DynamoDBResponseError: DynamoDBResponseError: 400 Bad Request 
{'Message': 'Expected null', '__type': 'com.amazon.coral.service#SerializationException'} 

我不處理需要處理的東西嗎?

+0

是什麼你博託版本? (''boto .__ version__'') – yadutaf

+0

我正在運行2.5.2。即使我刪除了attributes_to_get變量,我也會得到這個錯誤 – ensnare

+0

db.layer1.region.name和db.layer1.Version是怎麼回事? – yadutaf

回答

2

上有掃描線的錯誤:

results = table.scan(attributes_to_get={'id'}, 
     max_results=10) 

,而不是

results = table.scan(attributes_to_get=['id'], 
     max_results=10) 

編輯:

這適用於2.5.2的Boto

import boto 

db = boto.connect_dynamodb() 

table = db.get_table('MyTable') 
res = table.scan(attributes_to_get=['id'], max_results=10) 

for i in res: 
    print i 
+0

當我做出這種變化,我得到了一個不同的錯誤,沒有結果:TypeError:set(['id'])不是JSON可序列化 – ensnare

+0

這是我用花括號得到的那個... – yadutaf

+0

我認爲問題是顯示結果的循環中的某處。當我拿出那部分時,我不會再犯錯誤了。 – ensnare

相關問題