Failed to parse JSON from clightning-api response
In the c-lightning version 0.7+ there was a new class added Millisatoshis in python api lib. Some API calls returns object of type "Millisatoshi" which is impossible to parse as raw json input with python json lib. When trying to execute script i get following error:
Traceback (most recent call last): File "pay_without_invoice.py", line 103, in
flag = pay_without_invoice(nodeid, amount) File "pay_without_invoice.py", line 54, in pay_without_invoice print(json.dumps(route,sort_keys=True,indent=2)) File "/usr/local/lib/python3.6/json/init.py", line 238, in dumps **kw).encode(obj) File "/usr/local/lib/python3.6/json/encoder.py", line 201, in encode chunks = list(chunks) File "/usr/local/lib/python3.6/json/encoder.py", line 428, in _iterencode yield from _iterencode_list(o, _current_indent_level) File "/usr/local/lib/python3.6/json/encoder.py", line 325, in _iterencode_list yield from chunks File "/usr/local/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict yield from chunks File "/usr/local/lib/python3.6/json/encoder.py", line 437, in _iterencode o = _default(o) File "/usr/local/lib/python3.6/json/encoder.py", line 180, in default o.class.name) TypeError: Object of type 'Millisatoshi' is not JSON serializable
My c-lightning version: v0.7.0-36-g92c08cd workaround: simply print output "as is", this will cause readability of output, but still works.
lines i've changed:
46c46,47
< print(json.dumps(res,sort_keys=True,indent=2))
---
> #print(json.dumps(res,sort_keys=True,indent=2))
> print(res)
54c55,56
< print(json.dumps(route,sort_keys=True,indent=2))
---
> #print(json.dumps(route,sort_keys=True,indent=2))
> print(route)
93c95,96
< print(json.dumps(fullroute,sort_keys=True,indent=2))
---
> #print(json.dumps(fullroute,sort_keys=True,indent=2))
> print(fullroute)