channels/asgi 3.x imcompatibility with the code on 2.x versions

15 views
Skip to first unread message

Zhaoxun Yan

unread,
Nov 30, 2021, 9:16:11 AM11/30/21
to Django users
Hi there!

I have posted this issue like 3 months ago.

And there are many others encountering similar problem, like this:

The similarity is that the codes were running all-right under older 2.x versions,
but encounter the same error on which-ever 3.x versions of django-channels.

Would you please tell us where must be modified to be able to run on 3.x ?

Thanks a lot!

Bernard Mallala

unread,
Nov 30, 2021, 10:13:27 AM11/30/21
to Django users
This kind of error happens when working with classes. When you create methods for a class, you must always pass self as the first argument
self designates the object in which it is called. You have to pass self as the first argument for each method.
Does this help ?

Zhaoxun Yan

unread,
Dec 2, 2021, 3:02:41 AM12/2/21
to Django users
So far as our code and the code of another user, we have passed self as the first argument in the definition of a function/method.

relating code in consumers.py:

from channels.generic.websocket import AsyncWebsocketConsumer import json
class Trade(AsyncWebsocketConsumer):
  async def my_send(self, data):
    if isinstance(data, dict):
      d = json.dumps(data)
    else:
      d = str(data)
      await self.send(d)

Another user's code:
class TestConsumer(WebsocketConsumer):
  def connect(self):
Reply all
Reply to author
Forward
0 new messages