From 72fb2674117ee8c3c1cafa17512e524ea437f966 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: May 05 2016 14:43:36 +0000 Subject: ipalib.rpc: Send base64-encoded data as string under Python 3 Python 3's JSON library cannot deal with bytes, so decode base64-encoded data to string. Part of the work for https://fedorahosted.org/freeipa/ticket/4985 Reviewed-By: Martin Basti Reviewed-By: Petr Spacek --- diff --git a/ipalib/rpc.py b/ipalib/rpc.py index abc5575..207149e 100644 --- a/ipalib/rpc.py +++ b/ipalib/rpc.py @@ -298,7 +298,10 @@ def json_encode_binary(val, version): new_list = [json_encode_binary(v, version) for v in val] return new_list elif isinstance(val, bytes): - return {'__base64__': base64.b64encode(val)} + encoded = base64.b64encode(val) + if not six.PY2: + encoded = encoded.decode('ascii') + return {'__base64__': encoded} elif isinstance(val, Decimal): return {'__base64__': base64.b64encode(str(val))} elif isinstance(val, DN):