From d057b913716189d0136e93cee1fcefd1b7679bbb Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 15 Aug 2016 17:34:33 -0700 Subject: [PATCH] xfer_util: work on py2+py3 wormhole.send takes bytes, but the utility functions take strings. So encode the JSON blob before sending, and decode it on the way back out. --- src/wormhole/xfer_util.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wormhole/xfer_util.py b/src/wormhole/xfer_util.py index 41f9c9f..dfc0e1e 100644 --- a/src/wormhole/xfer_util.py +++ b/src/wormhole/xfer_util.py @@ -34,7 +34,7 @@ def receive(reactor, appid, relay_url, code, use_tor=None, on_code=None): if on_code: on_code(code) data = yield wh.get() - data = json.loads(data) + data = json.loads(data.decode("utf-8")) offer = data.get('offer', None) if not offer: raise Exception( @@ -43,7 +43,7 @@ def receive(reactor, appid, relay_url, code, use_tor=None, on_code=None): msg = None if 'message' in offer: msg = offer['message'] - wh.send(json.dumps({"answer": {"message_ack": "ok"}})) + wh.send(json.dumps({"answer": {"message_ack": "ok"}}).encode("utf-8")) else: raise Exception( @@ -87,10 +87,10 @@ def send(reactor, appid, relay_url, data, code, use_tor=None, on_code=None): "offer": { "message": data } - }) + }).encode("utf-8") ) data = yield wh.get() - data = json.loads(data) + data = json.loads(data.decode("utf-8")) answer = data.get('answer', None) yield wh.close() if answer: