jrief/django-websocket-redis

Websocket closing errors out in Django 1.11

Closed this issue · 3 comments

Responsible snippet (wsgi_server.py:148):

logger.warning('WebSocketError: {}'.format(excpt), exc_info=sys.exc_info())
response = http.HttpResponse(status=1001, content='Websocket Closed')

Stack trace:

Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/ws4redis/uwsgi_runserver.py", line 28, in receive
return uwsgi.websocket_recv_nb()
OSError: unable to receive websocket message
WARNING:django.request:WebSocketError: unable to receive websocket message
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/ws4redis/wsgi_server.py", line 131, in __call__
recvmsg = RedisMessage(websocket.receive())
File "/usr/local/lib/python3.6/dist-packages/ws4redis/uwsgi_runserver.py", line 31, in receive
raise WebSocketError(e)
ws4redis.exceptions.WebSocketError: unable to receive websocket message
ValueError: HTTP status code must be an integer from 100 to 599.
File "/usr/local/lib/python3.6/dist-packages/ws4redis/uwsgi_runserver.py", line 28, in receive

The cause is HTTP status code validation added in Django v1.11: django/django@190d2ff

i.e. 100 <= self.status_code <= 599.

@jrief sorry if this is documented somewhere and i missed it, but this issue still persists raise ValueError('HTTP status code must be an integer from 100 to 599.') (Django==1.11.3) and i see that this status code is still 1001 in the main branch

response.status_code = 1001

Is there a reason for it being a non standard HTTP response code? Thanks!

jrief commented

From my understanding at that time, this was the correct Websocket HTTP code. Shall it be changed?

Argh, I’m still running 0.4.7 in that environment, thought I’m using the latest version, should work just fine after upgrading. Thanks!!
If django continues adding validations to the HttpResponseBase class we might have to move away from using HttpResponse to be able to use websocket status codes. Right now they are only checking on init