1

I am trying to pass a python dictionary to a rabbitmq queue via pika, this is probably a python problem and not rabbitmq itself. I am getting an error as stated above and here is my code:

def PingAddScan(deviceID, ipAddress, deviceHistory, item, date, apiURL, browserConId):
    if PingDevice(deviceID, ipAddress):
        BasicScan(ipAddress, deviceID, item, apiURL)
        deviceHistory[deviceID] = date

        # After the basic scan we are going to need to push a message back to the user to say
        # that the pathfinder has successfully found the device, and it should prompt the user
        # what he wants to scan
        print browserConId + " : " + deviceID
        channelOutbound.queue_declare(queue='outboundMessaging', durable=True)
        message = {"browserConnectionID": browserConId, "data": "FOUND", "deviceID": deviceID}
        print str(message)
        channelOutbound.basic_publish(exchange='messaging',
                              routing_key='outbound',
                              body=message)

and here is the full stack trace:

    Traceback (most recent call last):
  File "pathfinderAllocator.py", line 454, in <module>
    channel.start_consuming()
  File "/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 1755, in start_consuming
    self.connection.process_data_events(time_limit=None)
  File "/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 715, in process_data_events
    self._dispatch_channel_events()
  File "/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 518, in _dispatch_channel_events
    impl_channel._get_cookie()._dispatch_events()
  File "/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 1384, in _dispatch_events
    evt.body)
  File "pathfinderAllocator.py", line 439, in callback
    PingAddScan(deviceID, ipAddress, deviceHistory, new_device, date, data, browser_connectionid)
  File "pathfinderAllocator.py", line 337, in PingAddScan
    body=message)
  File "/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 2052, in basic_publish
    mandatory, immediate)
  File "/usr/local/lib/python2.7/site-packages/pika/adapters/blocking_connection.py", line 2138, in publish
    immediate=immediate)
  File "/usr/local/lib/python2.7/site-packages/pika/channel.py", line 421, in basic_publish
    (properties, body))
  File "/usr/local/lib/python2.7/site-packages/pika/channel.py", line 1324, in _send_method
    self.connection._send_method(self.channel_number, method, content)
  File "/usr/local/lib/python2.7/site-packages/pika/connection.py", line 2137, in _send_method
    self._send_message(channel_number, method, content)
  File "/usr/local/lib/python2.7/site-packages/pika/connection.py", line 2164, in _send_message
    content[1][start:end]).marshal())
TypeError: unhashable type
Johnathon64
  • 1,280
  • 1
  • 20
  • 45
  • Looks like something to do with the last line `basic_publish`. These type errors generally occur when something mutable (such as a list) is used as a dictionary key. – Moon Cheesez Jun 24 '16 at 12:05
  • Hi Moon, I am only using strings as dictionary key, and the values are also strings – Johnathon64 Jun 24 '16 at 12:15
  • 2
    `body` in RabbitMQ is binary data, so you need either convert your dict into string as `import json; json.dumps(yourdict)` or you can pickle it. http://stackoverflow.com/questions/4342176/how-do-i-serialize-a-python-dictionary-into-a-string-and-then-back-to-a-diction – Novitoll Dec 20 '16 at 13:32

0 Answers0