python - 尝试发送带有代理属性的 Azure 服务总线消息时出现 400 错误

标签 python azure azureservicebus

我有一个小型 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/

相关文章:

c# - trye 上的 Azure 服务总线异常完成消息

没有运行时的 Azure 服务总线传入请求

azure - Azure 服务总线异常中的 "SystemTracker"是什么?

python - 用于重命名以空格或句点结尾的文件夹的递归脚本

python - 修补 Python 模块时 Django 中的 Gevent 异常

python - 减小 basemap 中使用的标记的大小并获得全屏

azure - 为表单识别器 2.0 添加 Azure 逻辑应用步骤存在内置连接问题

python - 检查 db 是否包含运行 Python 的 Google App Engine 上的 1000 个 ID 中的一个或多个

java - Azure Android Java 客户端

PHP Azure WebJob - 失败并退出代码 255(但在 Kudu 上工作正常)