Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to send a dictionary to RabbitMQ (unhashable type: 'slice')

I want to send a messge to RabbitMQ in a dictionary format:

import pika

# ....
my_msg = {}
my_msg["a"] = 1
my_msg["a"]["b"] = 2
channel.basic_publish(exchange="", routing_key="some_key", body=my_msg)

And an error I get:

TypeError: unhashable type: 'slice'

Note that I have plenty of my_msg and each of them has a few keys, so I need somehow to be able to send a list dictionaries to RabbitMQ.

How can I do that? Or are there other options?

like image 659
Alan Coromano Avatar asked Feb 08 '23 20:02

Alan Coromano


1 Answers

You need to serialize your dictionaries into strings and send them over RabbitMQ.

See this question

like image 101
Alik Avatar answered Feb 12 '23 10:02

Alik