Nick Sologoub
Nick Sologoub

Reputation: 734

Getting 400 error when trying to send an azure service bus message with broker properties

I have small python app that sends information to my azure service bus. I've noticed that each message has "broker_properties" dictionary and there is a property named "Label" that I can access later on from the service bus.

I am trying to send my message populating that property:

properties = {"Label":label}
msg = Message(bytes(messagebody, "utf-8"), bus_service, broker_properties=properties)
bus_service.send_queue_message("queue", msg)

But this doesn't seem to work. When the command above is executed I get back an error from Azure:

The value '{'Label': 'testtest'}' of the HTTP header 'BrokerProperties' is invalid.

Is this a bug in Python Azure SDK or am I doing something wrong?

Upvotes: 0

Views: 855

Answers (1)

Peter Pan
Peter Pan

Reputation: 24138

According to your code, the issue was caused by using a Python dict object as the value of the broker_properties, but the broker_properties value should be a json string. Please refer to the test code in Azure SDK for Python on GitHub.

So please modified your code as below.

properties = '{"Label": "%s"}' % label

Or

import json
properties = json.dumps({"Label":label})

Upvotes: 2

Related Questions