I am using requests
module. And, the data returned is unicode which contains the response(dictionary) from a server. Is there a way to pretty print the unicoded dictionary?
This response returned looks like this:
u'<<200:{"id":"12345","key_x":"41341e2277422","name":"xyz","key_y":"000566b8-1f52-5b38c","marked_for_removal":false,"max_capacity":3831609642556,"total_capacity":0,"total_reserved_capacity":0}'
or this:
u'>>GET https://x.x.x.x:8888/services/rest/abc : {'headers': {'content-type': 'application/json;charset=UTF-8', 'Accept': 'application/json, text/javascript, */*; q=0.01'}, 'params': {}, 'timeout': 30, 'verify': False}'
I want to print it in the following manner:
u'<<200:
{"id":"12345",
"key_x":"41341e2277422",
"name":"xyz",
"key_y":"000566b8-1f52-5b38c",
"marked_for_removal":false,
"max_capacity":3831609642556,
"total_capacity":0,
"total_reserved_capacity":0}'
i.e. the json, in between, should be formatted and the string can remain as it is.
I've tried converting data to string and printing it but that doesn't work.
import pprint
pprint.pprint(data.encode('utf-8'), width=1)