Channels: Error during WebSocket handshake: Unexpected response code: 500

Created on 26 Jun 2018  路  9Comments  路  Source: django/channels

hello everyone , i am new to channels and trying to make a chat app by following the documentation .
i followed each step . But i am facing this problem
(index):17 WebSocket connection to 'ws://127.0.0.1:8000/ws/chat/test10/' failed: Error during WebSocket handshake: Unexpected response code: 500
(anonymous) @ (index):17
and (index):17 is
var chatSocket = new WebSocket('ws://'+window.location.host+'/ws/chat/'+roomName+'/');
please help . and thanks in advance

Most helpful comment

Hola! Estuve siguiendo el tutorial y tambi茅n tuve el mismo error.. En Ubuntu 18.04 LTS

Lo solucion茅 haciendo la instalaci贸n de redis:

sudo apt install redis-server

Ya qu茅 en la secci贸n de pruebas arrojaba error cuando ejecutaba en la shell de Django:

>> async_to_sync(channel_layer.receive)('test_channel')

Luego que hice la instalaci贸n de redis el ejemplo se ejecut贸 con 茅xito.

All 9 comments

A 500 error means you have a problem in your Django code - look at the console that is running runserver to see what it is and fix it. It's not a Channels-specific problem.

Hola! Estuve siguiendo el tutorial y tambi茅n tuve el mismo error.. En Ubuntu 18.04 LTS

Lo solucion茅 haciendo la instalaci贸n de redis:

sudo apt install redis-server

Ya qu茅 en la secci贸n de pruebas arrojaba error cuando ejecutaba en la shell de Django:

>> async_to_sync(channel_layer.receive)('test_channel')

Luego que hice la instalaci贸n de redis el ejemplo se ejecut贸 con 茅xito.

@andrewgodwin thanks, i fix the problem

@JesusD2405 's solution also works..but as for me it was much simpler, I has forgotten to run the redis server!

So first check if the redis server is running

@andrewgodwin thanks, i fix the problem

Which OS are you using?
Can anybody please explain how to fix this problem?

------------- Edit -------------
Found this at documentation :

pip install -U asgi_redis

------------- Edit -------------

@andrewgodwin thanks, i fix the problem

How i'm also facing the same error.How did you detect the error?

@kshitij3199 can you please tell me how you fixed that???

@kshitij3199 i am getting same error in my django code by using asyncconsumer.

@deftydev @Ubaid-Parvaiz its been a while since you guys asked, but it turned out the issue was:

consumers.ChatRoomConsumer

in chat/routing.py was supposed to be:

consumers.ChatRoomConsumer.as_asgi()

Was this page helpful?
0 / 5 - 0 ratings