使用自定义标头发送Stomp.py失败

时间:2017-02-13 14:28:05

标签: python activemq stomp.py

我目前正在通过python Stomp.py库将消息从自定义系统推送到ActiveMQ实例。当我提供带有自定义标题的字典作为"标题"发送命令中的参数。

destination = self.subscription_id.queue_name
# Connect to the server
conn.connect(username=$username,
             password=$password,
             headers={})
# Send the actual message out
conn.send(destination, self.body, headers=self.header)
conn.disconnect()

由于某种原因,标题无法向我提供此错误:

ValueError: dictionary update sequence element #0 has length 1; 2 is required

堆栈跟踪的最后一部分:

File "/custom_addons/activemq_message.py", line 124, in send_to_queue
conn.send(destination, self.body, headers=self.header)

File "/usr/local/lib/python2.7/dist-packages/stomp/protocol.py", line 151, in send
headers = utils.merge_headers([headers, keyword_headers])

File "/usr/local/lib/python2.7/dist-packages/stomp/utils.py", line 166, in merge_headers
headers.update(header_map)

这不管是不是在哪里,我实际上都在字典中提供任何东西,或者只发出一个空的。

我也独立于连接级别或发送(或两者)提供标头。

似乎在某些时候将标题转换为字符串,但我无法弄清楚这是否是故意的。我也不知道如何解决这个问题。

任何线索都会受到赞赏。

1 个答案:

答案 0 :(得分:0)

找到原因,在代码的其他部分中,标头存储在字符串字段中。它随后尝试在字典的位置发送一个unicode。

由于我无法编辑源代码,因此我使用“ast”模块的方法“literal_eval”将unicode转换为字典并且它可以工作。