Discussion:
Django with Channels 2.1.1 Error During WebSocket handshake 404
Robert Fox
2018-11-17 04:06:19 UTC
Permalink
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
--
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.
Andrew Godwin
2018-11-17 06:34:24 UTC
Permalink
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
Post by Robert Fox
I am working on a project using Django and Channels 2.1.1. Everything is
'WebSocket connection to 'ws://IP/ws/lobby/' failed: Error during WebSocket
handshake: Unexpected response code: 404 ' which originates from the line
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
--
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
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
<https://groups.google.com/d/msgid/django-users/16ed620b-c05f-4392-8d84-6cbd85436ca2%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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/CAFwN1uq_EsgV2jt-PzMFsL1%2BAnQqEX0r4XHjLKPa5D_XZcfi4w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Robert Fox
2018-11-18 01:29:30 UTC
Permalink
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?
Post by Andrew Godwin
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/d9967d46-d2ac-4030-96aa-016a77b17f74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Robert Fox
2018-11-18 02:39:50 UTC
Permalink
I managed to get it working, turns out I forgot to install and configure
Redis. I now have a working web app with channels.
Post by Robert Fox
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?
Post by Andrew Godwin
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/d76dce1e-601e-4713-b028-2c1d0e832a4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...