Django with Channels 2.1.1 Error During WebSocket handshake 404

1,163 views
Skip to first unread message

Robert Fox

unread,
Nov 16, 2018, 11:12:09 PM11/16/18
to Django users
I am working on a project using Django and Channels 2.1.1. Everything is working splendidly on my home PC but when I deploy to AWS I get the error: 'WebSocket connection to 'ws://IP/ws/lobby/' failed: Error during WebSocket handshake: Unexpected response code: 404 ' which originates from the line in my HTML where I establish the chat socket :
var chatSocket = new WebSocket(
'ws://' + window.location.host + '/ws/' + roomName + '/'
);
I am using nginx and gunicorn to run my Django application on the host machine.
When I went to the Channels 2 tutorial it has a section for testing communication between the channels layer and Redis using the
Django Shell which I tested and works.
My full code can be seen at https://github.com/Rob-Fox/Chat2

Thank you

Andrew Godwin

unread,
Nov 17, 2018, 1:35:07 AM11/17/18
to django...@googlegroups.com
You cannot use gunicorn to run WebSockets or other async code - you need an ASGI server, like Daphne or uvicorn. Switch to one of those and it should start working.

Andrew

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/16ed620b-c05f-4392-8d84-6cbd85436ca2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Robert Fox

unread,
Nov 17, 2018, 8:29:30 PM11/17/18
to Django users
Thank you Andrew, I have now configured Nginx to route /ws/ to port 9000 where Daphne is configured. This has fixed my 404 handshake error and now I have a handshake error 500. Any thoughts?

Robert Fox

unread,
Nov 17, 2018, 9:39:50 PM11/17/18
to Django users
I managed to get it working, turns out I forgot to install and configure Redis. I now have a working web app with channels.
Reply all
Reply to author
Forward
0 new messages