Home > database >  How to get receipt handle from sqs queue response, getting(TypeError 'sqs.Message' object
How to get receipt handle from sqs queue response, getting(TypeError 'sqs.Message' object

Time:02-05

I have one queue I'm sending some message in that and want to get receipt handle from output response.

messages = queue.receive_messages()
print(messages)

I am receiving this type of response:

[sqs.Message(queue_url='someurl', receipt_handle='abcd')]

Now I want to extract only receipt handle from the response, here what I have tried

message = messages[0]
receipt_handle = message['receipt_handle']
print(receipt_handle)

but I'm getting below error:

TypeError 'sqs.Message' object is not subscriptable

How can I get receipt_handle from response?

CodePudding user response:

The sqs.Message object uses attributes:

message.receipt_handle

See the documentation: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs.html#message


Your attempt only works if you use the boto3-client, then the response is a dict. See https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs.html#message

  • Related