title: TypeError: object.__init__() takes exactly one argument (the instance to initialize) WebSocket DISCONNECT /public_chat/1/ [127.0.0.1:50083]
body: <p>I am following <code>Coding With Mitch</code> chat app and I am stuck on an Error.</p>
  <p>When I run server, it is working fine but when I refresh the browser then it is showing</p>
  <blockquote>
  <p>TypeError: object.<strong>init</strong>() takes exactly one argument (the instance to initialize)
  WebSocket DISCONNECT /public_chat/1/ [127.0.0.1:50083]</p>
  </blockquote>
  <p>settings.py</p>
  <pre><code>CHANNEL_LAYERS = {
      'default': {
          'BACKEND': 'channels_redis.core.RedisChannelLayer',
          'CONFIG': {
              &quot;hosts&quot;: [('127.0.0.1', 6379)],
          },
      },
  }
  </code></pre>
  <p>routing.py</p>
  <pre><code>from channels.auth import AuthMiddlewareStack
  from channels.routing import ProtocolTypeRouter, URLRouter
  from channels.security.websocket import AllowedHostsOriginValidator
  from django.urls import path, re_path
  
  from chat.consumers import ChatConsumer
  from public_chat.consumers import PublicChatConsumer
  from notification.consumers import NotificationConsumer
  
  
  application = ProtocolTypeRouter({
      'websocket': AllowedHostsOriginValidator(
          AuthMiddlewareStack(
              URLRouter([
                      re_path('', NotificationConsumer.as_asgi()),
                      re_path('chat/&lt;room_id&gt;/', ChatConsumer.as_asgi()),
                      re_path('public_chat/&lt;room_id&gt;/', PublicChatConsumer.as_asgi()),
              ])
          )
      ),
  })
  </code></pre>
  <p><code>websockets.py</code></p>
  <pre><code>import json
  
  from asgiref.sync import async_to_sync
  
  from ..consumer import AsyncConsumer, SyncConsumer
  from ..exceptions import (
      AcceptConnection,
      DenyConnection,
      InvalidChannelLayerError,
      StopConsumer,
  )
  
  
  class WebsocketConsumer(SyncConsumer):
  
  groups = None
  
      def __init__(self, *args, **kwargs):
         if self.groups is None:
              self.groups = []
  
      def websocket_connect(self, message):
  
          try:
              for group in self.groups:
                  async_to_sync(self.channel_layer.group_add)(group, 
  self.channel_name)
          except AttributeError:
              raise InvalidChannelLayerError(
                  &quot;BACKEND is unconfigured or doesn't support groups&quot;
              )
              try:
              self.connect()
          except AcceptConnection:
              self.accept()
          except DenyConnection:
              self.close()
  
      def connect(self):
          self.accept()
  
      def accept(self, subprotocol=None):
  
      super().send({&quot;type&quot;: &quot;websocket.accept&quot;, &quot;subprotocol&quot;: subprotocol})
  
      def websocket_receive(self, message):
  
          if &quot;text&quot; in message:
              self.receive(text_data=message[&quot;text&quot;])
          else:
              self.receive(bytes_data=message[&quot;bytes&quot;])
  
          def receive(self, text_data=None, bytes_data=None):
    
          pass
  
      def send(self, text_data=None, bytes_data=None, close=False):
  
          if text_data is not None:
              super().send({&quot;type&quot;: &quot;websocket.send&quot;, &quot;text&quot;: text_data})
          elif bytes_data is not None:
              super().send({&quot;type&quot;: &quot;websocket.send&quot;, &quot;bytes&quot;: bytes_data})
          else:
              raise ValueError(&quot;You must pass one of bytes_data or text_data&quot;)
          if close:
              self.close(close)
  
      def close(self, code=None):
  
          if code is not None and code is not True:
              super().send({&quot;type&quot;: &quot;websocket.close&quot;, &quot;code&quot;: code})
          else:
              super().send({&quot;type&quot;: &quot;websocket.close&quot;})
  
      def websocket_disconnect(self, message):
  
          try:
              for group in self.groups:
                  async_to_sync(self.channel_layer.group_discard)(
                      group, self.channel_name
                  )
          except AttributeError:
              raise InvalidChannelLayerError(
                  &quot;BACKEND is unconfigured or doesn't support groups&quot;
              )
          self.disconnect(message[&quot;code&quot;])
          raise StopConsumer()
  
      def disconnect(self, code):
  
          pass
  
  
  class JsonWebsocketConsumer(WebsocketConsumer):
  
  
      def receive(self, text_data=None, bytes_data=None, **kwargs):
           if text_data:
              self.receive_json(self.decode_json(text_data), **kwargs)
          else:
              raise ValueError(&quot;No text section for incoming WebSocket frame!&quot;)
  
       def receive_json(self, content, **kwargs):
   
          pass
  
      def send_json(self, content, close=False):
   
          super().send(text_data=self.encode_json(content), close=close)
  
      @classmethod
      def decode_json(cls, text_data):
          return json.loads(text_data)
  
      @classmethod
      def encode_json(cls, content):
          return json.dumps(content)
  
  
  class AsyncWebsocketConsumer(AsyncConsumer):
  
  
      groups = None
  
      def __init__(self, *args, **kwargs):
          super().__init__(self,*args, **kwargs)
          if self.groups is None:
              self.groups = []
  
      async def websocket_connect(self, message):
   
        try:
              for group in self.groups:
                  await self.channel_layer.group_add(group, self.channel_name)
          except AttributeError:
              raise InvalidChannelLayerError(
                  &quot;BACKEND is unconfigured or doesn't support groups&quot;
              )
          try:
              await self.connect()
          except AcceptConnection:
              await self.accept()
          except DenyConnection:
              await self.close()
  
      async def connect(self):
          await self.accept()
  
      async def accept(self, subprotocol=None):
   
          await super().send({&quot;type&quot;: &quot;websocket.accept&quot;, &quot;subprotocol&quot;: subprotocol})
  
      async def websocket_receive(self, message):
   
         if &quot;text&quot; in message:
              await self.receive(text_data=message[&quot;text&quot;])
          else:
              await self.receive(bytes_data=message[&quot;bytes&quot;])
  
      async def receive(self, text_data=None, bytes_data=None):
    
          pass
  
      async def send(self, text_data=None, bytes_data=None, close=False):
  
          if text_data is not None:
              await super().send({&quot;type&quot;: &quot;websocket.send&quot;, &quot;text&quot;: text_data})
          elif bytes_data is not None:
              await super().send({&quot;type&quot;: &quot;websocket.send&quot;, &quot;bytes&quot;: bytes_data})
          else:
              raise ValueError(&quot;You must pass one of bytes_data or text_data&quot;)
          if close:
              await self.close(close)
  
      async def close(self, code=None):
     
         if code is not None and code is not True:
              await super().send({&quot;type&quot;: &quot;websocket.close&quot;, &quot;code&quot;: code})
          else:
              await super().send({&quot;type&quot;: &quot;websocket.close&quot;})
  
      async def websocket_disconnect(self, message):
  
          try:
              for group in self.groups:
                  await self.channel_layer.group_discard(group, self.channel_name)
           except AttributeError:
              raise InvalidChannelLayerError(
                  &quot;BACKEND is unconfigured or doesn't support groups&quot;
              )
          await self.disconnect(message[&quot;code&quot;])
          raise StopConsumer()
  
      async def disconnect(self, code):
  
          pass
  
  
  class AsyncJsonWebsocketConsumer(AsyncWebsocketConsumer):
  
  
      async def receive(self, text_data=None, bytes_data=None, **kwargs):
          if text_data:
              await self.receive_json(await self.decode_json(text_data), **kwargs)
          else:
              raise ValueError(&quot;No text section for incoming WebSocket frame!&quot;)
  
      async def receive_json(self, content, **kwargs):
  
          pass
  
      async def send_json(self, content, close=False):
      &quot;&quot;&quot;
      Encode the given content as JSON and send it to the client.
      &quot;&quot;&quot;
      await super().send(text_data=await self.encode_json(content), close=close)
  
  @classmethod
  async def decode_json(cls, text_data):
      return json.loads(text_data)
  
  @classmethod
  async def encode_json(cls, content):
      return json.dumps(content)
  </code></pre>
  <p><code>settings.py</code>:</p>
  <pre><code>ASGI_APPLICATION = 'brain.routing.application'
  
  CHANNEL_LAYERS = {
      'default': {
          'BACKEND': 'channels_redis.core.RedisChannelLayer',
          'CONFIG': {
              &quot;hosts&quot;: [('127.0.0.1', 6379)],
          },
      },
  }
  </code></pre>
  <p><strong>When i try to inspect the browser page then i got one error</strong></p>
  <p><a href="https://i.stack.imgur.com/LzNZu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LzNZu.png" alt="enter image description here" /></a></p>
  <p>Any help would be appreciated. Thank You in Advance</p>