WebSocket django channels doesn't work with postman

Django Channels Throw error with postman while working well with Html.

I'm following Django Socket Tutorial

"here's the error showing in Django".

WebSocket HANDSHAKING /ws/chat/roomName/ []
WebSocket REJECT /ws/chat/roomName/ []
WebSocket DISCONNECT /ws/chat/roomName/ []

"Error showing in postman when connecting to ws://"

Sec-WebSocket-Version: 13
Sec-WebSocket-Key: fSSuMD2QozIrgywqTX38/A==
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

My Code asgi.py

django_asgi_app = get_asgi_application()

import digital_signage.playlist_management.routing

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


class ChatConsumer(WebsocketConsumer):
    def connect(self):
        print("self", self)

This happens because of ALLOWED_HOST in settings. You can put * if you on development mode but it will affect the whole project. Instead you can do something like below

You can wrap asgi.py with OriginValidator (can be import from channels.security.websocket)

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


Back to Top