Azure-sdk-for-python: Service Bus type Message doesn't have a method to get the payload

Created on 25 Sep 2019  路  4Comments  路  Source: Azure/azure-sdk-for-python

How can I get the payload from a Message other than calling message.__str__()?

I've spent some time looking for it and I couldn't find any. It's just weird to call it that way. I tried body() method but it returns a complex object instead of the actual "body" by which I mean the payload.

Tutorials and examples also give the standard print(message).

Am I missing something?

Tried the reference too..

https://docs.microsoft.com/en-us/python/api/azure-servicebus/azure.servicebus.common.message.message?view=azure-python

Client Service Bus customer-reported

Most helpful comment

Thanks @epomatti - you can access the data using the body attribute you described. This field simply returns a generator.
Messages can contain multiple sections of data, which is why it's present this way. So you could interact with it multiple ways:

data = next(message.body)
data = list(message.body)[0]

All 4 comments

Hi @epomatti thanks for asking, I'm tagging it for the right team take a look at this.

Thanks @epomatti - you can access the data using the body attribute you described. This field simply returns a generator.
Messages can contain multiple sections of data, which is why it's present this way. So you could interact with it multiple ways:

data = next(message.body)
data = list(message.body)[0]

@annatisch thanks that did the trick, python newbie here

Thanks for working with Microsoft on GitHub! Tell us how you feel about your experience using the reactions on this comment.

Was this page helpful?
0 / 5 - 0 ratings