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
        }))

5
1
Jinzal 105 points

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

5 (1 Votes)
0
3.83
6
James Clark 105 points

                                    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)

3.83 (6 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source