I'm currently pushing messages from a custom system via the python Stomp.py library to an ActiveMQ instance. This fails when I provide a dictionary with custom headers as the "headers" parameter in the send command.
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.
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.