Doist / todoist-python

DEPRECATED The official Todoist Python API library
MIT License
534 stars 73 forks source link

Throttling and response status codes. #100

Open stacksjb opened 2 years ago

stacksjb commented 2 years ago

Hello,

I have been working on a python sync script to sync Todoist and Canvas tasks, which has been working quite well.

Today I got busy trying to code some additional features into my script, and it suddenly quit working. When I tried to log into Todoist on the web to check, I got error message

"Error: {"error":"Too many requests. Limits reached. Try again later","error_code":35,"error_extra":{"event_id":"703f9f8f1553433c815aa1cbd5d8fe58","retry_after":513},"error_tag":"LIMITS_REACHED","http_code":429} Event ID: 12405665f4884a32b7438ae9d09e4cc9

It is now 6+ hours later, and while the desktop and web client functionality seems to have returned, the submitted tasks from my script are still not showing up in the WebUI, and executing print(todoist_api) after running todoist.api.commit() returns TodoistAPI(<not synchronized>)

I could not locate any documentation on this response, can anyone point me towards a more verbose output or anything that might help me determine what might be going on?

goncalossilva commented 2 years ago

This looks like a bug. Since the response body from 429 is valid JSON, we might be parsing it correctly here. Problem is, we seem rely on this failing (and throwing) to do error handling. Without it, the SDK assumes it was able to sync, and tasks will be lost. We should check for unexpected response codes (4XX/5XX) and act accordingly.

Are you able to reinitiate sync for the missing tasks? The library doesn't know about them anymore, judging from that output. 😕

stacksjb commented 2 years ago

I agree, I've run into this with lots of other libraries where I have needed to add "if response.statuscode =" into the logic.

Based on https://developer.todoist.com/rest/v1/#overview, we should be flagging anything that is not a 2xx response (typical response should be 200 or 204), a 4xx or 5xx response should be considered incomplete.

stacksjb commented 2 years ago

I attempted to reinstate sync but it continue to fail; I attempted with another account and then another apikey and they both worked.

So it looks like if you annoy the Todoist API too much you might need to regenerate your APIkey to get things working again.