簡體   English   中英

嘗試發送帶有代理屬性的Azure Service Bus消息時出現400錯誤

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

我有一個小型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字符串。 請參考GitHub上適用於Python的Azure SDK中的測試代碼

因此,請如下修改您的代碼。

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

要么

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM