I am trying to connect django channel but it is rejected my request


First, please do not post screenshots of code or data. Copy/paste the text into your post, surrounded by lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```.

We’re going to need more details.

  • What does your asgi.py file look like?
  • What does your routing.py file look like? (Or whatever other file you may have defining websocket urls - if any)
  • How are you running this?
from channels.generic.websocket import WebsocketConsumer

class MyConsumer(WebsocketConsumer):
    groups = ["broadcast"]

    def connect(self):

    def receive(self, text_data=None, bytes_data=None):
        self.send(text_data="Hello world!")
        self.send(bytes_data="Hello world!")   

    def disconnect(self, close_code):
import os
from .consumer import MyConsumer
from django.urls import path
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")

django_asgi_app = get_asgi_application()

application = ProtocolTypeRouter(
        "http": django_asgi_app,
        "websocket": AllowedHostsOriginValidator(

Why are you calling close in your connect function? Why do you have two calls to accept?

Have you worked your way through the official Channels tutorial to the point where you understand what it’s doing?