N
N
NikClik2018-12-02 23:42:57
Django
NikClik, 2018-12-02 23:42:57

How to send over a dict channel?

I'm using channels 2.0 (this is important), I have a method in the consumer that sends over a dict channel. BUT, the problem is that it will give me an error when sending "Object of type 'set' is not JSON serializable":
consumer.py:

class ChangesConsumer(JsonWebsocketConsumer):

    def connect(self):
        async_to_sync(self.channel_layer.group_add)('users', self.channel_name)
        self.accept()

    def disconnect(self, close_code):
        async_to_sync(self.channel_layer.group_discard)('users', self.channel_name)
        self.dispatch()

    def receive_json(self, content, **kwargs):
        self.send_json(content['text'])

it is logical that I have a dict in content['text'] that I need to send. I tried to solve the problem with "Object of type 'set' is not JSON serializable", did not bring any results. So, can someone give me ideas / links to a solution for transferring a dictionary over a channel?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NaName, 2018-12-03
@NikClik

dict -> JSON and everything will work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question