websocket._exceptions.WebSocketBadStatusException: Handshake status 500 Internal server error code example

Example 1: websocket._exceptions.WebSocketBadStatusException: Handshake status 500 Internal server error

application = ProtocolTypeRouter({
    'websocket': AuthMiddlewareStack(
        URLRouter([
            url(r'^debug/$', debug_consumers.DebugConsumer)
        ])
    ),
})

Example 2: websocket._exceptions.WebSocketBadStatusException: Handshake status 500 Internal server error

class DebugConsumer(WebsocketConsumer):
    def connect(self):
        self.channel_layer.group_add("debug", self.channel_name)
        self.accept()

    def disconnect(self, close_code):
        self.channel_layer.group_discard("debug", self.channel_name)

    def receive(self, text_data):
        text_data_json = json.loads(text_data)
        message = text_data_json['message']

        self.send(text_data=json.dumps({
            'message': "Echo:" + message
        }))

Example 3: websocket._exceptions.WebSocketBadStatusException: Handshake status 500 Internal server error

import pytest
import websocket
from channels.testing import WebsocketCommunicator, ChannelsLiveServerTestCase
from django.test import TestCase, override_settings

class SomeLiveTests(ChannelsLiveServerTestCase):
    available_apps = [ ]

    def test_live_with_live_server(self):
        ws_debug_url = "{}/debug/".format(self.live_server_ws_url)
        print("Connecting to liver server {}".format(ws_debug_url))
        ws = websocket.create_connection(ws_debug_url)