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

Binary message receiving errors out with Python 3 #236

Closed erikreed closed 7 years ago

erikreed commented 7 years ago

Stack trace:

INFO:django.request:websocket.receive: Unknown error must be str, not bytes
Other Exception: must be str, not bytes
Traceback (most recent call last):
  File ".../lib/python3.6/site-packages/ws4redis/wsgi_server.py", line 123, in __call__
    recvmsg = RedisMessage(websocket.receive())
  File ".../lib/python3.6/site-packages/ws4redis/websocket.py", line 224, in receive
    raise e
  File ".../lib/python3.6/site-packages/ws4redis/websocket.py", line 215, in receive
    return self.read_message()
  File ".../lib/python3.6/site-packages/ws4redis/websocket.py", line 195, in read_message
    message += payload
TypeError: must be str, not bytes

Cause is the message initialization:

message = ""

from: here.

The message is then concatenated with the websocket payload.

This works fine in Python 2 because the following is acceptable:

"string" + b"bytes"

But of course, in Python 3 we get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't convert 'bytes' object to str implicitly

PR incoming.