kiwiz / gkeepapi

An unofficial client for the Google Keep API.
MIT License
1.53k stars 114 forks source link

Traceback error upon syncing #85

Closed ChocoTonic closed 4 years ago

ChocoTonic commented 4 years ago

Trying to create notes using the examples in the docs to make sure things are working and I'm getting this error when I try to sync

def sync():
    print("syncing...")
    keep.sync()

note = keep.createNote("Todo", "Eat breakfast")
note.pinned = True
note.color = gkeepapi.node.ColorValue.Blue
sync()
Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\node.py", line 213, in load
    self._load(raw)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\node.py", line 622, in _load
    self._created = self.str_to_dt(raw['created'])
KeyError: 'created'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "w:\Github\General\Python\Working\Sandbox6.py", line 31, in <module>
    sync()
  File "w:\Github\General\Python\Working\Sandbox6.py", line 12, in sync
    keep.sync()
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\__init__.py", line 1034, in sync
    self._parseNodes(changes['nodes'])
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\__init__.py", line 1064, in _parseNodes
    node.load(raw_node)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\node.py", line 213, in load
    self._load(raw)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\node.py", line 1192, in _load
    super(TopLevelNode, self)._load(raw)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\node.py", line 1045, in _load
    self.timestamps.load(raw['timestamps'])
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\node.py", line 215, in load
    raise_from(exception.ParseException('Parse error in %s' % (type(self)), raw), e)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\future\utils\__init__.py", line 403, in raise_from
    exec(execstr, myglobals, mylocals)
  File "<string>", line 1, in <module>
gkeepapi.exception.ParseException: Parse error in <class 'gkeepapi.node.NodeTimestamps'>
kiwiz commented 4 years ago

I'm unable to reproduce the issue - can you try testing with another account?

corus87 commented 4 years ago

I get the same error when trying to add a item. But it's working, only the exception is raising.

ChocoTonic commented 4 years ago

I'm unable to reproduce the issue - can you try testing with another account?

So I have 2 different accounts that I'm trying this with. One has almost no notes and the other I have many many notes and the initial sync takes up to 90s. Occasionally creating a list will work but not a note on the latter account and I get a traceback error, but on the empty account, there's no error and the list/note creating is fine.

not sure what it could be. Is there a way to locally cache the notes so it doesn't take forever to initially sync the account? I read the documentation but it wasn't clear on what I'm actually supposed to do to save it locally

kiwiz commented 4 years ago

See the docs here to get a dump of the node in question.

Wrt to resume support, the docs are here. You can find a sample implementation here

ChocoTonic commented 4 years ago

This is the code that I attempted could this be an issue with my system time? I have it set to auto set the date I'm not sure if it is because my test with my empty account still works normally

import sys
from plyer import notification
import keyring
import gkeepapi
from time import sleep

def sync():
    print("syncing...")
    keep.sync()

# Credentials
username = "xxxgmail.com"
password = "XXX

print("logging in...")
keep = gkeepapi.Keep()
keep.login(username, password)
print("logged in...")

try:
    gnote = keep.createNote("Title", "Text")

    glist = keep.createList(
        "Title", [("Item 1", False), ("Item 2", True)]  # Not checked  # Checked
    )
except gkeepapi.exception.ParseException as e:
    print(e.raw)

# script complete notification
sync()

This is what the debug error looks like. I'm not sure if the try except code worked.

image

This is the output in the console when I run without debugging. Did the try except work in this case?

logging in...
logged in...
syncing...
Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\node.py", line 213, in load
    self._load(raw)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\node.py", line 622, in _load
    self._created = self.str_to_dt(raw['created'])
KeyError: 'created'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "w:\Github\General\Python\GoogleKeep\gkeep3.py", line 38, in <module>
    sync()
  File "w:\Github\General\Python\GoogleKeep\gkeep3.py", line 12, in sync
    keep.sync()
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\__init__.py", line 1034, in sync
    self._parseNodes(changes['nodes'])
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\__init__.py", line 1064, in _parseNodes
    node.load(raw_node)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\node.py", line 213, in load
    self._load(raw)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\node.py", line 1192, in _load
    super(TopLevelNode, self)._load(raw)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\node.py", line 1045, in _load
    self.timestamps.load(raw['timestamps'])
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\gkeepapi\node.py", line 215, in load
    raise_from(exception.ParseException('Parse error in %s' % (type(self)), raw), e)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python38\lib\site-packages\future\utils\__init__.py", line 403, in raise_from
    exec(execstr, myglobals, mylocals)
  File "<string>", line 1, in <module>
gkeepapi.exception.ParseException: Parse error in <class 'gkeepapi.node.NodeTimestamps'>
kiwiz commented 4 years ago

I don't think your time is the issue. Looks like a note of yours doesn't have an expected field - either because the format changed recently or because it's very old.

The exception is happening in the sync() function. If you include that in the try: block, it should print out the contents of the NodeTimestamps JSON that's causing the problem.

catanzaromj commented 4 years ago

I get the same error after adding a list. When I log in and immediately sync, no issue. Same with deleting a list. But if I add a list and sync, I get the same message as @ChocoTonic, and it does still sync like @corus87

ChocoTonic commented 4 years ago

Here is the code I tried following your suggestion: https://github.com/kiwiz/gkeepapi/issues/85#issuecomment-627768017

import sys
import keyring
import gkeepapi
from time import sleep

def sync():
    try:
        print("syncing...")
        keep.sync()
    except gkeepapi.exception.ParseException as e:
        print(e.raw)

# Credentials
username = "xxx@gmail.com"
password = "xxx"

print("logging in...")
keep = gkeepapi.Keep()
keep.login(username, password)
print("logged in...")

try:
    gnote = keep.createNote("Title", "Text")

    glist = keep.createList(
        "Title", [("Item 1", False), ("Item 2", True)]  # Not checked  # Checked
    )
except gkeepapi.exception.ParseException as e:
    print(e.raw)

# script complete notification
sync()

Here is the output:

logging in...
logged in...
syncing...
{'kind': 'notes#timestamps', 'updated': '2020-05-13T10:14:47.734Z', 'trashed': '1970-01-01T00:00:00.000Z', 'userEdited': '2020-05-13T10:14:47.734Z'}

Hopefully this helps with figuring out what the issue could be

fjlp commented 4 years ago

Im getting the same error since today gkeepapi.exception.ParseException: Parse error in <class 'gkeepapi.node.NodeTimestamps'> , I moved keep.sync() line to the end of my code in order to complete all my tasks in it.

bitowl commented 4 years ago

I got this error today as well with a NodeTimestamps object that has no created date. image

I fixed this temporarily by adding if 'created' in raw else None to line 622 of node.py.

ChocoTonic commented 4 years ago

oh nice! that actually worked for this small example!

I rewrote a little to compartmentalize my stuff:

# https://gkeepapi.readthedocs.io/en/latest/#id1

import sys
from plyer import notification
import keyring
import gkeepapi
from time import sleep

def sync(keep):
    try:
        print("syncing...")
        keep.sync()
    except gkeepapi.exception.ParseException as e:
        print(e.raw)

def login(username, password):
    print("logging in...")
    keep = gkeepapi.Keep()
    keep.login(username, password)
    print("logged in...")
    return keep

def main(keep):
    note = keep.createNote("Todo", "Eat breakfast")
    note.pinned = True
    note.color = gkeepapi.node.ColorValue.Gray

# Credentials
username = "xxx@gmail.com"
password = "xxx"

try:
    keep = login(username, password)
    main(keep)
except gkeepapi.exception.ParseException as e:
    print(e.raw)

# script complete notification
sync(keep)
kiwiz commented 4 years ago

Thanks for the debugging work, all. Seems that the servers now only send the created field for nodes that the client has not seen yet. Pushed up a new version with a fix.