Django web ports cannot send messages to channel

I am using network sockets with Redis on Django. Django works fine on a macOS server, but I started running it on a Redhat Linux server, and now the server gives me this error whenever I send a packet through websockets:

ERROR - server - HTTP/WS send decode error:
    Cannot dispatch message on channel
    u'daphne.response.fzdRCEVZkh!nqhIpaLfWb' (unknown)

Note: while I receive the error message, the package will be received correctly.

I could not find any resources for this error.

I followed the official instructions for the channels.

+4
source share
1 answer

( ), , , , (-) :

, , , . - , . , Group.discard , .

, impl channels.generic.websockets.WebsocketConsumer. disconnect .

: , foo . , , :

from channels import Group
from channels.generic.websockets import JsonWebsocketConsumer

class MyConsumer(JsonWebsocketConsumer):

    groupname = 'foo'

    def connect(self, message, **kwargs):
        # send an accept or the connection will be dropped automatically
        self.message.reply_channel.send({"accept": True})
        # add the channel to the broadcast group
        Group(self.groupname).add(message.reply_channel)
        # do the rest of logic that should happen on connection established
        ...

    def disconnect(self, message, **kwargs):
        Group(self.groupname).discard(message.reply_channel)
        # do the rest of logic that should happen on disconnect
        ...
+3
source

Source: https://habr.com/ru/post/1674239/


All Articles