AWS Boto:scan()未知关键字'limit'

时间:2014-10-12 14:24:47

标签: python python-2.7 amazon-web-services amazon-dynamodb database-scan

之前有人遇到过这个问题吗?

import boto

conn = boto.dynamodb.connect_to_region('eu-west-1', aws_access_key_id=aws_key, aws_secret_access_key=aws_secret)
table = conn.get_table('TweetSample')

print table.scan(limit=1)

错误:

Traceback (most recent call last):
File "test.py", line 9, in <module>
print table.scan(limit=1)
File "table.py", line 518, in scan
return self.layer2.scan(self, *args, **kw)
TypeError: scan() got an unexpected keyword argument 'limit'
[Finished in 0.4s with exit code 1]

我甚至都不知道......

1 个答案:

答案 0 :(得分:0)

根据文档,scan methodboto.dynamodb.table.Table(由boto.dynamodb.layer2.Layer2.get_table返回)不接受limit,但max_results

结果是一台发电机。所以,如果你想打印它,你应该迭代它:

import boto.dynamodb

conn = boto.dynamodb.connect_to_region(
    'eu-west-1',
    aws_access_key_id=aws_key,
    aws_secret_access_key=aws_secret)
table = conn.get_table('TweetSample')
for row in table.scan(max_results=1):
    print row

或将其转换为序列:

print list(table.scan(max_results=1))