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

Sync stops with error: "[script.trakt] trakt.interfaces.base: Request failed: "POST /sync/history" - 429: "Rate limit exceeded" (Rate Limit Exceeded)" #619

Open
waywit opened this issue Jun 9, 2023 · 8 comments

Comments

@waywit
Copy link

waywit commented Jun 9, 2023

Expected Behavior

The Trak.tv add-on should respect the defined API usage rules defined by trakt.tv here: trakt/api-help#220

Current Behavior

The Trakt.tv add-on does not respect the boundaries and receives a "[script.trakt] trakt.interfaces.base: Request failed: "POST /sync/history" - 429: "Rate limit exceeded" (Rate Limit Exceeded)" Error.
This issue is not shown in UI, so that the user thinks that everything is fine, but now there are many information missing in trakt.tv.

Possible Solution

I have some ideas to implement:

  1. per run only submit the maximum allowed requests to the trat.tv API. BUT inform the user about this and he can try again 10 minutes later to submit the missing changes.
  2. Respect the request limits in software and wait/slowdown the requests or cut them into smaller packets so that every change can be submitted in on single run, but this one will take longer.

Steps to Reproduce (for bugs)

  1. Setup Kodi with enough change that should be submitted to trakt.tv
  2. Enable Debug logging in Trakt.tv add-on
  3. Start an update by running the Trakt.tv add-on
  4. Check Logfile for message after collecting big amount of changes: "[script.trakt] trakt.interfaces.base: Request failed: "POST /sync/history" - 429: "Rate limit exceeded" (Rate Limit Exceeded)"

Context

Actually my Kodi library cannot be synced with trakt, only single changes are transported to trakt.tv.

Your Environment

  • Version used: 3.5.0
  • Kodi version used: 20.1
  • Operating System and version: Ubuntu 22.04.2 LTS
@waywit
Copy link
Author

waywit commented Jan 1, 2024

Hi, 6 month without any response :-( Is the Trakt Addon still in development? I would like to know if I can use Trakt.TV in the future anymore or if I will stuck here with not possible to update my trait.tv status?

Maybe the solution can be found in the trakt.tv API information: https://trakt.docs.apiary.io/#introduction/required-headers

"All API methods are rate limited. A 429 HTTP status code is returned when the limit has been exceeded. Check the headers for detailed info, then try your API call in Retry-After seconds."

Thanks and best regards...

@razzeee
Copy link
Collaborator

razzeee commented Jan 2, 2024

This would be needed to be implemented in https://github.com/fuzeman/trakt.py/

@waywit
Copy link
Author

waywit commented Jan 3, 2024

Hi, thanks for your response. I have done a dirty Fix in your script... I found out, that the rate limit was violated between to API requests doing different things, time between both calls <1s... So I added a 1 second "time.sleep(1)" which solved the actual issue and my collection can be synced again... but I am not sure where this needs to be originally be fixed...

As you can see here that there are 4 POST API calls in 1 second, where 3 of them violate the API restrictions by trakt.tv:

2024-01-03 20:09:15.378 T:2503099 debug <general>: [script.trakt] resources.lib.syncEpisodes: [traktUpdateEpisodes] Shows to update {'shows': [{'title': ...}]}]}]} 2024-01-03 20:09:15.584 T:2503099 debug <general>: [script.trakt] urllib3.connectionpool: https://api.trakt.tv:443 "POST /sync/history HTTP/1.1" 201 None 2024-01-03 20:09:15.585 T:2503099 debug <general>: [script.trakt] resources.lib.syncEpisodes: [traktUpdateEpisodes] Shows to update {'shows': [{'title': ...}]}]}]} 2024-01-03 20:09:15.709 T:2503099 debug <general>: [script.trakt] urllib3.connectionpool: https://api.trakt.tv:443 "POST /sync/history HTTP/1.1" 429 None 2024-01-03 20:09:15.709 T:2503099 warning <general>: [script.trakt] trakt.interfaces.base: Request failed: "POST /sync/history" - 429: "Rate limit exceeded" (Rate Limit Exceeded) 2024-01-03 20:09:15.709 T:2503099 debug <general>: [script.trakt] resources.lib.syncEpisodes: [traktUpdateEpisodes] Shows to update {'shows': [{'title': ...}]}]}]} 2024-01-03 20:09:15.838 T:2503099 debug <general>: [script.trakt] urllib3.connectionpool: https://api.trakt.tv:443 "POST /sync/history HTTP/1.1" 429 None 2024-01-03 20:09:15.838 T:2503099 warning <general>: [script.trakt] trakt.interfaces.base: Request failed: "POST /sync/history" - 429: "Rate limit exceeded" (Rate Limit Exceeded) 2024-01-03 20:09:15.839 T:2503099 debug <general>: [script.trakt] resources.lib.syncEpisodes: [traktUpdateEpisodes] Shows to update {'shows': [{'title': ...}]}]}]} 2024-01-03 20:09:15.963 T:2503099 debug <general>: [script.trakt] urllib3.connectionpool: https://api.trakt.tv:443 "POST /sync/history HTTP/1.1" 429 None 2024-01-03 20:09:15.963 T:2503099 warning <general>: [script.trakt] trakt.interfaces.base: Request failed: "POST /sync/history" - 429: "Rate limit exceeded" (Rate Limit Exceeded) 2024-01-03 20:09:15.963 T:2503099 debug <general>: [script.trakt] resources.lib.syncEpisodes: [traktUpdateEpisodes] Finished with 0 error(s)

From my point of view the issue is not an mass update issue, but a fast POST API issue... Perhaps you can take a look on it and maybe find a fix for it, where you can wait 1 second between every POST API call?

Many thanks in advance :-)

@razzeee
Copy link
Collaborator

razzeee commented Jan 4, 2024

As stated, that should be done in trakt.py (both projects have been around before trakt introduced api limits)

fuzeman/trakt.py#86

@waywit
Copy link
Author

waywit commented Jan 4, 2024

Puh... the linked issue is older than 3 years, without any progress :-( I think the chances to get fixed are very low, maybe time to look for an alternative for trakt.tv...

@dan-riley
Copy link

I ran into this issue as well, installing the plugin on an existing Kodi installation and trying to sync old history. I was also able to fix it with a sleep call. Specifically, in .kodi\addons\script.trakt\resources\lib\traktapi.py, under addToHistory(self, mediaObject), before result = Trakt['sync/history'].add(mediaObject), added time.sleep(1). I also noticed there's quite a few things it tries to sync each time that don't seem to exist in Trakt, like special episodes...so would like to figure out how to get it to stop doing that each time!

@nathanpw
Copy link

Hello and thank you for this great Kodi plugin/script! I have run into the same rate limiting issue/error. For me it seems to be due to many show updates, which eventually clear itself if you run it multiple times. Sometimes, updates of episodes that aren't tracked on tmdb (which keep trying to update) also cause issue (or "blockages"). Anyhow the time.sleep(1) hack did make this more consistent and reliable for me. However, as mentioned it is an improper fix and a proper implementation should be made upstream in the trakt api library being used.

I did notice a different trakt api python interface had a solution: moogar0880/PyTrakt#138

I was hoping to look at this more, unfortunately I don't have the time. I would assume implementing a new trakt api interface would be more time consuming and problematic.

Just thought I would share my experience with this. Thanks again for your efforts and support!

@razzeee
Copy link
Collaborator

razzeee commented Jan 15, 2024

Looking at that repo, it also seems pretty dead, so not sure if that would improve anything

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

4 participants