, . Python Unicode, , , u'', , .
, , JSON - . .json() , response .text - JSON, .
>>> ast.literal_eval(json.dumps(c))
Fails because you flip it cto JSON first and then try to parse it as a Python literal. This does not work because Python is not JSON; in particular, has null, and the other has None.
So maybe you want to change Unicode strings to bytes? For example, encoding them as UTF8, this may work:
def to_utf8(d):
if type(d) is dict:
result = {}
for key, value in d.items():
result[to_utf8(key)] = to_utf8(value)
elif type(d) is unicode:
return d.encode('utf8')
else:
return d
Or something like that, but I don’t know why you need it.
source
share