我有一个小型 python 应用程序,可以将信息发送到我的 azure 服务总线。我注意到每条消息都有“broker_properties”字典,并且有一个名为“Label”的属性,我稍后可以从服务总线访问该属性。
我正在尝试发送填充该属性的消息:
properties = {"Label":label}
msg = Message(bytes(messagebody, "utf-8"), bus_service, broker_properties=properties)
bus_service.send_queue_message("queue", msg)
但这似乎不起作用。当执行上面的命令时,我从 Azure 返回一个错误:
The value '{'Label': 'testtest'}' of the HTTP header 'BrokerProperties' is invalid.
这是 Python Azure SDK 中的错误还是我做错了什么?
最佳答案
根据您的代码,该问题是由于使用 Python dict 对象作为 broker_properties
的值引起的,但 broker_properties
值应该是 json 字符串。请引用测试code在 GitHub 上的 Azure SDK for Python 中。
所以请修改您的代码如下。
properties = '{"Label": "%s"}' % label
或者
import json
properties = json.dumps({"Label":label})
关于python - 尝试发送带有代理属性的 Azure 服务总线消息时出现 400 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40695229/