On Python 3 we need to make sure bytes get written to the websocket.

This commit is contained in:
Itamar Turner-Trauring 2021-01-12 11:38:37 -05:00
parent 116c59142d
commit d99c94753c

View File

@ -5,6 +5,8 @@ from __future__ import (
division,
)
from future.builtins import str
import json
from autobahn.twisted.resource import WebSocketResource
@ -49,7 +51,11 @@ class TokenAuthenticatedWebSocketServerProtocol(WebSocketServerProtocol):
"""
# probably want a try/except around here? what do we do if
# transmission fails or anything else bad happens?
self.sendMessage(json.dumps(message))
encoded = json.dumps(message)
if isinstance(encoded, str):
# On Python 3 dumps() returns Unicode...
encoded = encoded.encode("utf-8")
self.sendMessage(encoded)
def onOpen(self):
"""