jrief / django-websocket-redis

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

Subscribe to User Notification does not work #267

Open jotauses opened 6 years ago

jotauses commented 6 years ago

Simply http://django-websocket-redis.readthedocs.io/en/latest/usage.html does not work. Copied and paste from the docs and only works the broadcast message.

https://stackoverflow.com/questions/50862982/django-websockets-with-redis

2DKot commented 6 years ago

Is your user logged in? Try session notification http://django-websocket-redis.readthedocs.io/en/latest/usage.html#subscribe-to-session-notification - does it work?

jotauses commented 6 years ago

Yes, the user is logged in. No, It does not work with sessions neither, only works the broadcast.

2DKot commented 6 years ago

Try to debug authorization during socket connection. Place breakpoint to https://github.com/jrief/django-websocket-redis/blob/abcddaad2f579d71dbf375e5e34bc35eef795a81/ws4redis/wsgi_server.py#L63 and refresh page. Is request.user successfully assigned here?

jotauses commented 6 years ago

No, the request.user is a AnonymousUser and I'm logged in... Just as it says in the documentation I'm using django-redis-session but the sessionid tokens are differents between views.py and wsgi_server.py

If I get the sessionid from the views.py's request and I put it in the var session_key of the line 65 of wsgi-server.py works perfectly, so... the problem is that the sessionid tokens are differents... how can I solve that?

I reset the cookies and cache and now the cookie is always null in the wsgi_server.py because a error. The trace is:

Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 138, in run self.finish_response() File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 180, in finish_response self.write(data) File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 279, in write self._write(data) File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\wsgiref\handlers.py", line 453, in _write result = self.stdout.write(data) File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\socketserver.py", line 775, in write self._sock.sendall(b) ConnectionAbortedError: [WinError 10053] Se ha anulado una conexión establecida por el software en su equipo host [27/Jun/2018 08:48:05] "GET /ws/foobar?subscribe-user/ HTTP/1.1" 500 59