boto / boto3

AWS SDK for Python
https://aws.amazon.com/sdk-for-python/
Apache License 2.0
9.05k stars 1.87k forks source link

Strange response #899

Closed pjz closed 7 years ago

pjz commented 7 years ago

Hi! I've got some code that does:

def _domains():
          _db = boto.client('sdb')
          domains = []
          response = _db.list_domains()
          while 'NextToken' in response:
              domains.extend(response['DomainNames'])
              response = _db.list_domains(NextToken=response['NextToken'])
          domains.extend(response['DomainNames'])
          return domains

...but after getting KeyError: 'DomainNames' I printed out response and was surprised to find it was:

{'ResponseMetadata': {
    'RetryAttempts': 0, 
    'HTTPStatusCode': 200, 
    'BoxUsage': '0.0000071759', 
    'RequestId': '4b262d7a-c389-3fbb-b3ea-d6f193579d4c', 
    'HTTPHeaders': {'transfer-encoding': 'chunked', 
         'vary': 'Accept-Encoding',
         'server': 'Amazon SimpleDB', 
         'connection': 'keep-alive',
         'date': 'Mon, 21 Nov 2016 21:25:32 GMT',
         'content-type': 'text/xml'}
}}

...any idea why that might be? The docs don't say anything about a response like that.

stealthycoin commented 7 years ago

If you only have ResponseMetadata in your response it probably means you got an empty response from the server. Try setting more debug logging with boto.set_stream_logger('') and see what response body has. Mine is empty since I have no SDB resources.

As to why it has an empty response, I have no idea. You can ask questions directly related to the service on their forum https://forums.aws.amazon.com/forum.jspa?forumID=38

pjz commented 7 years ago

Honestly, I rewrote it to use DynamoDB, which had no such unwelcome surprises.

stealthycoin commented 7 years ago

Glad you got a working solution.

AayushiG28 commented 5 years ago

Hi, I am getting this response when i am invoking my endpoint.

Not able to get the correct response.

{'ResponseMetadata': {'RequestId': '21863f68-aa40-4405-b8be-36abd9b90ef7', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '21863f68-aa40-4405-b8be-36abd9b90ef7', 'x-amzn-invoked-production-variant': 'AllTraffic', 'date': 'Sat, 1 Jun 2019 10:25:02 GMT', 'content-type': 'application/json', 'content-length': '3173'}, 'RetryAttempts': 0}, 'ContentType': 'application/json', 'InvokedProductionVariant': 'AllTraffic', 'Body': <botocore.response.StreamingBody object at 0x7f4c089e0198>}

max-rocket-internet commented 4 years ago

This happens when there is no results. For example if you're using a region where there is nothing to return from the query.

JRileyH commented 3 months ago

Why is it okay that the docs don't specify this as a possible response? How are people supposed to build predictable handling of the return value of this function if it not explained anywhere what can be returned. I'm working on SQS client create_queue: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs/client/create_queue.html

The docs specifiy either return syntax of:

{
    'QueueUrl': 'string'
}

OR it enumerates a list of potential exceptions.

Returning a dictionary with ResponseMetadata is not included in either of those realities so where is this documented? I really don't understand why its satisfactory that an obscure, closed github issue thead is somehow the only place I found mention of this potential response..