From d99c94753c1e222e0e5cb9eca79369f5f955f123 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 12 Jan 2021 11:38:37 -0500 Subject: [PATCH] On Python 3 we need to make sure bytes get written to the websocket. --- src/allmydata/web/logs.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/allmydata/web/logs.py b/src/allmydata/web/logs.py index 0ba8b17e9..896dce418 100644 --- a/src/allmydata/web/logs.py +++ b/src/allmydata/web/logs.py @@ -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): """