我正在尝试使用扫描功能从数据库中的表中检索任何10个结果,如下所示:
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 :(得分:2)
扫描线上有错误:
results = table.scan(attributes_to_get={'id'},
max_results=10)
而不是
results = table.scan(attributes_to_get=['id'],
max_results=10)
编辑:
这适用于Boto 2.5.2
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