jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
894 stars 221 forks source link

IOError: unable to complete websocket handshake #247

Closed ghost closed 6 years ago

ghost commented 6 years ago

I am getting IOError: unable to complete websocket handshake when trying to connect to a websocket. On my local machine, I am able to connect and exchange messages, but when I try to deploy it behind Nginx and uWSGI I get this error. I am instantiating different instances of uWSGI for my Django application and Sockets. Traceback:

Traceback (most recent call last): File "/home/minus/minus_env/local/lib/python2.7/site-packages/ws4redis/wsgi_server.py", line 113, in call websocket = self.upgrade_websocket(environ, start_response) File "/home/minus/minus_env/local/lib/python2.7/site-packages/ws4redis/uwsgi_runserver.py", line 52, in upgrade_websocket uwsgi.websocket_handshake(environ['HTTP_SEC_WEBSOCKET_KEY'], environ.get('HTTP_ORIGIN', '')) IOError: unable to complete websocket handshake Starting late response on websocket Finish non-websocket response with status code: 500 [pid: 2140|app: 0|req: 1/1] 0.0.0.0 () {44 vars in 905 bytes} [Thu Oct 5 12:23:43 2017] GET /ws/live-score?subscribe-broadcast&publish-broadcast&echo => generated 38 bytes in 50 msecs (HTTP/1.1 500) 1 headers in 78 bytes (3 switches on core 999)

Nginx: version - 1.4.6

location /ws/ { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://unix:/home/minus/home-screen/uwsgi_socket.sock; }

uWSGI: version - 2.0.14

[uwsgi] virtualenv = /home/minus/minus_env/ chdir = /home/minus/home-screen/ http-socket = /home/minus/home-screen/uwsgi_socket.sock chmod-socket = 664 gevent = 1000 http-websockets = true workers = 2 master = true module = minus.websocket_wsgi:application

What am I doing wrong?

Rakin061 commented 6 years ago

Hello, I am getting exactly the same problem ?

Have you been able to find any solution for that ??

ghost commented 6 years ago

This issue happened for me as I had not instantiated workers. In local environment, I did not have to run them.

Rakin061 commented 6 years ago

Could you please help me more specifically about exactly what changes you have made to resolve this issue. I already mentioned I have been facing the same error and can't resolve it.

jrief commented 6 years ago

did you create two uwsgi instances, one for Django and one for WS?

ghost commented 6 years ago

Could you please provide more information about how you are trying to deploy?