Django channels error:- Could not connect to ws://,

IMO I think it is unable to find the route /ws/sc route but I dont understand why as I have linked it properly.

The error is give when I try to establish a connection using postman

Following is the postman error:-

Could not connect to ws://
Error: Unexpected server response: 404
Handshake Details
Request URL:
Request Method: GET
Status Code: 404 Not Found

Consumer class :-

from channels.consumer import AsyncConsumer, SyncConsumer

class MySyncConsumer(SyncConsumer):

def websocket_connect(self, event):
    print("Websocket Connected", event)
        'type': 'websocket.accept'
def websocket_receive(self, event):
    print("Message recieved", event)

def websocket_disconnect(self, event):
    print("Websocket Disconnected", event)

Routing class

from django.urls import path, re_path
from . import consumers

websocket_urlpatterns = [
    re_path(r'ws/sc/$', consumers.MySyncConsumer.as_asgi()),

Asgi class

import os
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
import core.routing

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gs3.settings')

application = ProtocolTypeRouter(
        "httpa": get_asgi_application(),
        "websocket": AuthMiddlewareStack(

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-*3c_890(%*-no1e64qvxtq^1su(8-pyb5t46p-kzpqu=1173%i'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True


# Application definition




ROOT_URLCONF = 'gs3.urls'

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [

ASGI_APPLICATION = 'gs3.asgi.application'

# Database

    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',

# Password validation

        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',

# Internationalization



USE_I18N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)

STATIC_URL = 'static/'

# Default primary key field type

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

It is giving 404 error as it is unable to locate ws/sc path. I have uploaded all classes in which I made changes, I am new to learning websocket but I positive that I have setup it correctly but still it is not able to connect

There is typo in the Asgi Class. Changing the httpa to http should fix this?

    "http": some_app,
    "websocket": some_other_app,
Back to Top