From baaa041b8a272e43c99f00f69fc645a2e92216db Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: May 05 2016 14:42:46 +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 c70b3a2..be1ae63 100644 --- a/ipalib/rpc.py +++ b/ipalib/rpc.py @@ -297,7 +297,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):