如何删除@strin3http//schemas.microsoft.com/2003/10/Serialization/?从python脚本中接收的服务总线队列接收?

Poo*_*hia 6 c# python serialization json azure

我已将 Azure 流分析作业的输出设置为以 JSON 序列化格式发送数据的服务总线队列。当我在 python 脚本中收到队列消息以及花括号中的数据时,我得到 @strin3http//schemas.microsoft.com/2003/10/Serialization/? 附加在前面。我无法修剪它,因为接收到的消息未被识别为字符串或消息。因此,我无法对数据进行反序列化。

Pet*_*Pan 3

该问题与 SO 线程互操作性 Azure 服务总线消息队列消息类似。

根据我的经验,从Azure Stream Analytics到Service Bus的数据是通过AMQP协议发送的,但Python中接收数据的协议是HTTP。多余的内容是AMQP在传输过程中产生的。

假设通过下面的代码接收消息,请参阅https://azure.microsoft.com/en-us/documentation/articles/service-bus-python-how-to-use-queues/#receive-messages-from -a-队列receive_queue_message具有False参数值的函数peek_lock包装了 REST API接收和删除消息(破坏性读取)

msg = bus_service.receive_queue_message('taskqueue', peek_lock=False)
print(msg.body)
Run Code Online (Sandbox Code Playgroud)

根据Azure Service Bus SDK for Python的源代码包含了这些函数receive_queue_messageread_delete_queue_message并且,我认为您可以直接从使用字符串公共函数或_create_message中删除多余的内容。msg.bodylstripstrip