Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wont decode page with json/collate - TypeError: datetime.time(0, 0) is not JSON serializable #195

Open
kenstack opened this issue Jun 17, 2016 · 1 comment

Comments

@kenstack
Copy link
Contributor

kenstack commented Jun 17, 2016

Im decoding history from a 722 and started to get crashes on decoding the second page. If I turn collate off it decodes just fine. When I turn --collate to get json output I get the following error

File "/usr/lib/python2.7/json/encoder.py", line 177, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: datetime.time(0, 0) is not JSON serializable

I put some prints into the python code - the offending record is below - all records before that parse just fine

RECORD 18 {'_type': 'ChangeBasalProfile_old_profile', '_description': 'ChangeBasalProfile_old_profile 2016-06-16T18:37:55 head[2], body[145] op[0x08]', 'timestamp': '2016-06-16T18:37:55', '_body': '0030000234000d3a000f2a00122400162400181c001a10001e1c0022260027360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', '_head': '080b', 'rate': 'offset', '_date': '77a5121010'}

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/35254500-wont-decode-page-with-json-collate-typeerror-datetime-time-0-0-is-not-json-serializable?utm_campaign=plugin&utm_content=tracker%2F522759&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F522759&utm_medium=issues&utm_source=github).
@kenstack
Copy link
Contributor Author

kenstack commented Aug 22, 2016

I continue to struggle with errors in decoding datetime in python using mm-decode-history-page.py now and again - Ive solved the problem by adding the following to the code

import datetime

json.JSONEncoder.default = lambda self,obj: (obj.isoformat() if isinstance(obj, datetime.datetime) else None)

now all of the files I had errors with decode to json just fine - Ill try to do a pull request if I remember how :)

Im not sure how openaps traps decoding errors, but I wonder if some of the issues people see with reading history are not bad pump reads (ie comm issues), but rather random decoding errors like this as the python code just crashes with no json output

the offending records - in my experience - generally are changes to basal profiles, carb ratios, etc - not bolus or temp basal history records

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant