KeyError: "checked" when trying to sync new checkbox in list
See original GitHub issueI’m getting a checkbox list from my Google Keep and assigning it to glist, adding a checked checkbox item and trying to sync. That code is:
glist = keep.get("*********")
glist.add('Item 3', True)
keep.sync()
I get the following error:
File "lib\site-packages\gkeepapi\node.py", line 1176, in load
self._checked = raw['checked']
KeyError: 'checked'
I poked around and it looks like when when line 559 in init.py is run, the variable “changes” is assigned with the checkbox not having a “checked” property. Here is line 559:
changes = self._keep_api.changes(
target_version=self._version,
nodes=[i.save() for i in self._findDirtyNodes()],
labels=[i.save() for i in self._labels.values()] if labels_updated else None,
)
if I stop right before that code is run and run the param snippet from above:
nodes=[i.save() for i in self._findDirtyNodes()]
you can see that the new ListItem has a property “checked = True”.
Stepping through line 559 in init.py takes you to line 269 in init.py, it’s the return for the self._keep_api.changes()
function:
return self.send(
url=self._base_url + 'changes',
method='POST',
json=params
The response you get from self.send() does not have the “checked” property anymore. It does have a “checked_ts_micro” property with a value of u'1521385638051000'
. It looks like some measure of when the box was checked. If I run the original code with the checked param as False, glist.add('Item 3', False)
,that “checked_ts_micro” property has a value of u'0'
.
This is as far as I gotten with investigating it. Not sure why it doesn’t return a “checked” property but it might be an easy fix to just add something like:
if: checked_ts_micro > 0:
self.checked = True
else:
self.checked = False
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
@danielwossenu Finally managed to reproduce it. Hopefully the above change should fix the issue!
There is a bug in the load(self, raw) function in node.py where a string is getting loaded into _version and then comparison is failing due to “TypeError: unorderable types: str() > int()” on line 872 of node.py
The value of _version is loaded from the JSON as a str if the baseVersion is present
Which throws the “TypeError: unorderable types: str() > int()” in the save function
I’ll do a pull request shortly.