简体   繁体   English

带有自定义标头的Stomp.py发送失败

[英]Stomp.py send with custom headers fails

I'm currently pushing messages from a custom system via the python Stomp.py library to an ActiveMQ instance. 我目前正在将消息从自定义系统通过python Stomp.py库推送到ActiveMQ实例。 This fails when I provide a dictionary with custom headers as the "headers" parameter in the send command. 当我提供带有自定义标头的字典作为send命令中的“标头”参数时,此操作将失败。

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()

For some reason, the header fails providing me with this error: 由于某种原因,标头无法为我提供此错误:

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

Last part of the stack trace: 堆栈跟踪的最后一部分:

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)

This is regardless of whereter or not I actually provide anything in the dictionary or just send out an empty one. 不管我在字典中实际提供什么内容,还是只发送空的内容,这都是不管的。

It is also independant of me providing headers at connection level or send (or both). 这也与我在连接级别或发送(或两者)提供标头无关。

It seems to be converting the header to a string at some point, but I cannot figure out if is this intentional or not. 似乎在某些时候将标头转换为字符串,但是我无法弄清楚这是否是故意的。 Neither can I find out how to fix this. 我也找不到解决方法。

Any clues would be appreciated. 任何线索将不胜感激。

Found the cause, in some other part of the code the header was stored in a string field. 找到了原因,在代码的其他部分中,标头存储在字符串字段中。 It subsequently try to send a unicode in the place of a dictionary. 随后,它尝试发送unicode代替字典。

Since I could not edit the source I used the "ast" module's method "literal_eval" to convert the unicode to a dictionary and it works. 由于无法编辑源代码,因此使用“ ast”模块的方法“ literal_eval”将unicode转换为字典,并且可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM