ensnare
ensnare

Reputation: 42033

DynamoDB scan function returns correct results, but with DynamoDBResponseError

I'm trying to retrieve any 10 results from a table in my database using the scan function as follows:

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

But then I get this error at the end (after the correct results are returned):

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

Am I not handling something that needs to be handled?

Upvotes: 2

Views: 833

Answers (1)

yadutaf
yadutaf

Reputation: 7132

There is a mistake on the scan line:

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

instead of

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

EDIT:

This works with 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

Upvotes: 2

Related Questions