【问题标题】:Stomp.py send with custom headers fails带有自定义标头的 Stomp.py 发送失败
【发布时间】:2017-07-01 13:54:58
【问题描述】:

我目前正在通过 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)

这与我实际上在哪里提供字典中的任何内容或只是发送一个空字典无关。

在连接级别或发送(或两者)提供标头也与我无关。

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

任何线索将不胜感激。

【问题讨论】:

    标签: python activemq stomp.py


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-09
      • 1970-01-01
      • 1970-01-01
      • 2014-01-03
      • 2012-03-07
      相关资源
      最近更新 更多