def _to_binary(body): from requests.compat import json as complexjson data = complexjson.dumps(body) if not isinstance(data, bytes): return data.encode('utf-8') else: return data