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

Client does not wish to upgrade to a websocket :Develop mode Runserver #193

Closed asennoussi closed 8 years ago

asennoussi commented 8 years ago

Hello, I'm trying to make the websocket work, but I'm a little bit confused. So I have few questions: This piece of code

from ws4redis.publisher import RedisPublisher
from ws4redis.redis_store import RedisMessage

redis_publisher = RedisPublisher(facility='foobar', broadcast=True)
message = RedisMessage('Hello World')
# and somewhere else
redis_publisher.publish_message(message)

Does it automatically create the route for /foobar? Also in developer mode, I get this error

Client does not wish to upgrade to a websocket

Full error code :

HandshakeError: Client does not wish to upgrade to a websocket
Traceback (most recent call last):
  File "/Users/Sshucchi/.virtualenvs/project/lib/python2.7/site-packages/ws4redis/wsgi_server.py", line 80, in __call__
    self.assure_protocol_requirements(environ)
  File "/Users/Sshucchi/.virtualenvs/project/lib/python2.7/site-packages/ws4redis/wsgi_server.py", line 49, in assure_protocol_requirements
    raise HandshakeError('Client does not wish to upgrade to a websocket')
HandshakeError: Client does not wish to upgrade to a websocket
Starting late response on websocket
Finish non-websocket response with status code: 400
[pid: 7278|app: 0|req: 1/1] 127.0.0.1 () {40 vars in 840 bytes} [Mon May 23 06:17:13 2016] GET /ws/foobar/ => generated 46 bytes in 1 msecs (HTTP/1.1 400) 1 headers in 68 bytes (3 switches on core 99)

So what I did is create a class

class MyTypicalView(View):
    def __init__(self, **kwargs):
        super(MyTypicalView, self).__init__(**kwargs)
        self.redis_publisher = RedisPublisher(facility='foo', broadcast=True)

    def dispatch(self, request, *args, **kwargs):
        welcome = RedisMessage('Hello everybody')  # create a welcome message to be sent to everybody
        self.redis_publisher.publish_message(welcome)
        return HttpResponse('test')

Add the url route url(r'^ws/socket/$', MyTypicalView.as_view(), name='socket'),

But I don't know if what I'm doing is the right thing. Please help.

PS: I'm not loading the templates synchronously. I'm connecting to websocket from chrome console, because I'm planning to include this in an angularjs project.

onkarmukherjee commented 6 years ago

Getting same error "Client does not wish to upgrade" Were you able to solve it?

Allan-Nava commented 6 years ago

How can I use the django-websocket redis with nginx webserver? I got this error:

HandshakeError: HTTP server protocol must be 1.1
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/ws4redis/wsgi_server.py", line 94, in __call__
    self.assure_protocol_requirements(environ)
  File "/usr/local/lib/python3.5/dist-packages/ws4redis/wsgi_server.py", line 57, in assure_protocol_requirements
    raise HandshakeError('HTTP server protocol must be 1.1')
ws4redis.exceptions.HandshakeError: HTTP server protocol must be 1.1
Starting late response on websocket
Finish non-websocket response with status code: 400