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

Trakt API Limits: API didn't respond properly, script will abort now #2162

Open
2 of 3 tasks
purplescorpion1 opened this issue Jan 27, 2025 · 19 comments
Open
2 of 3 tasks

Comments

@purplescorpion1
Copy link

purplescorpion1 commented Jan 27, 2025

Confirmation

  • I have read the README.md on the project homepage
  • I have checked if an identical issue or discussion already exists
  • I have tried downgrading to find version that can be used as a workaround

The problem

Possible linked to #2159

Using version 0.33.0

Although it does eventually work I get a lot of warnings and errors

HTTPSConnectionPool(host=`api.trakt.tv' , port=443): Read timed out

It tried two times then carried on

Then I get loads of

Bad Response - Response could not be parsed for plextraktsync.queue.TraktBatchWorker.add_to_collection()

Other responses succeed but some get

Error: Bad Response - Response could not be parsed
Details: Unable to parse JSON: Expecting value: line 1 column 1 (char 0)
Last call: plextraktsync.queue.TraktBatchWorker.add_to_collection =((defaultdict(<class followed by values for program
Got exception while working on <plextraktsync.queue.TraktBatchWorker.TraktBatchWorker object at 0x2c8082e2a0>: API didn't respond properly, script will abort now. Please try again later

Then it succeeds in some more and others get the above error

Think the last run I did was last week on version 0.32.7 and no issues there so something has either changed in the script or the API

Steps to reproduce the behavior

run plextraktsync sync

Error trace / logs

Expected behavior

no errors an everything sync

Inspect of problematic items

Workarounds

No response

Config file contents

Install method

pipx

Version

0.33.0

Python Version

3.12.8

Plex Server Version

1.41.4.9380-34f46d871

Operating System and Version

termux 0.119.0 running on android tv 9.1.2

@glensc
Copy link
Collaborator

glensc commented Jan 27, 2025

enable debug log and report again

@glensc
Copy link
Collaborator

glensc commented Jan 27, 2025

What I see is that trakt invented new status code 420

2025-01-27 20:20:43,965 DEBUG[urllib3.connectionpool]:https://api.trakt.tv:443 "POST /sync/collection HTTP/1.1" 420 None
2025-01-27 20:20:43,965 DEBUG[trakt.core]:RESPONSE [post] (https://api.trakt.tv/sync/collection): <Response [420]>

@glensc
Copy link
Collaborator

glensc commented Jan 27, 2025

https://trakt.docs.apiary.io/#introduction/status-codes

420 Account Limit Exceeded - list count, item count, etc

@purplescorpion1
Copy link
Author

purplescorpion1 commented Jan 27, 2025

Why do some succeed and others fail then? If its a limit exceeded wouldn't everything fail?

Some new things sync and other new things fail to sync

Also I don't see a 420 error in the output unless its not logged

Edit
So even though it failed it still synced everything

@purplescorpion1
Copy link
Author

purplescorpion1 commented Jan 27, 2025

I've turned on debug and still I don't see any 420 error on my output

after running it through a few time I'm no longer getting

HTTPSConnectionPool(host=`api.trakt.tv' , port=443): Read timed out

But I am getting all the other errors

Error: Bad Response - Response could not be parsed
Details: Unable to parse JSON: Expecting value: line 1 column 1 (char 0)
Last call: plextraktsync.queue.TraktBatchWorker.add_to_collection =((defaultdict(<class followed by values for program
Got exception while working on <plextraktsync.queue.TraktBatchWorker.TraktBatchWorker object at 0x2c8082e2a0>: API didn't respond properly, script will abort now. Please try again later

And it did actually sync my watched history

@purplescorpion1
Copy link
Author

purplescorpion1 commented Jan 27, 2025

glensc

ah I see the issue

Its a rate limit issue - its trying to sync too fast

Can you set a rate limiter on so it sends the requests more slowly - add a wait of a second or two between requests and then see if that works

@glensc
Copy link
Collaborator

glensc commented Jan 27, 2025

@purplescorpion1 doesn't look like you even looked at debug log, it's a file, not terminal output.

@glensc
Copy link
Collaborator

glensc commented Jan 27, 2025

From my testing, most of the syncing succeeds, scrobbling, mark as watched, rate, but adding to collection gives 420 error

the error response is not much useful. all I can extract is that some limit is 100

420 response headers dump

{
    'Date': 'Mon, 27 Jan 2025 20:20:04 GMT',
    'Content-Type': 'application/json',
    'Transfer-Encoding': 'chunked',
    'Connection': 'keep-alive',
    'x-frame-options': 'SAMEORIGIN',
    'x-xss-protection': '0',
    'x-content-type-options': 'nosniff',
    'x-download-options': 'noopen',
    'x-permitted-cross-domain-policies': 'none',
    'referrer-policy': 'strict-origin-when-cross-origin',
    'x-upgrade-url': 'https://trakt.tv/vip',
    'x-vip-user': 'false',
    'x-account-limit': '100',
    'vary': 'Accept-Encoding',
    'Content-Encoding': 'gzip',
    'x-ratelimit': '{"name":"AUTHED_API_POST_LIMIT","period":1,"limit":1,"remaining":0,"until":"2025-01-27T20:20:05Z"}',
    'Cache-Control': 'no-cache',
    'Set-Cookie': '_traktsession=*redacted*; path=/; HttpOnly; SameSite=Lax',
    'x-request-id': '*redacted*',
    'x-runtime': '0.016574',
    'cf-cache-status': 'DYNAMIC',
    'Server': 'cloudflare',
    'CF-RAY': '*redacted*',
    'alt-svc': 'h3=":443"; ma=86400'
}

@purplescorpion1
Copy link
Author

purplescorpion1 commented Jan 27, 2025

oh I see it in the file log - I was expecting a debug output in the console

yes there is a 420 error there

and also getting rate limit errors

WARNING[plextraktsync.decorators.rate_limit]:Rate Limit Exceeded for plextraktsync.queue.TraktMarkWatchedWorker.add_to_history(), retrying after 1 seconds (try: 1/5)
WARNING[plextraktsync.decorators.rate_limit]:Rate Limit Exceeded for plextraktsync.queue.TraktBatchWorker.add_to_collection(), retrying after 1 seconds (try: 1/5)

@glensc
Copy link
Collaborator

glensc commented Jan 27, 2025

It seems to me that if you retry an action that got 420, it will be promoted immediately to rate limit error

@glensc
Copy link
Collaborator

glensc commented Jan 27, 2025

So, it's likely this update:

but I don't understand what rate limit of 100 I'm hitting when I'm just registering collection?

I can have only 100 items in trakt collection? that's absurd!

@glensc
Copy link
Collaborator

glensc commented Jan 27, 2025

Looks like this is the end of this project.

No way I'm interested in trakt if the previous unlimited collection size is limited to just 100 items. I don't care (much) about other features, as I don't hit their limits (yet).

@glensc glensc pinned this issue Jan 27, 2025
@glensc glensc changed the title API didn't respond properly Trakt API Limits: API didn't respond properly, script will abort now Jan 27, 2025
@Untimed4598
Copy link

Looks like this is the end of this project.

No way I'm interested in trakt if the previous unlimited collection size is limited to just 100 items. I don't care (much) about other features, as I don't hit their limits (yet).

Yes, I agree here, adding it to collections was a great part of using this project, but I'd like to mention if you update your configs to no longer deal with the collection then you won't get any errors and the scrobbling part of the project still works as is.

The code still probably needs to get updated so it doesn't retry upon receiving 420 error message and probably mention a warning somewhere about the collection being limited to only 100 items.

@simonc56
Copy link
Collaborator

simonc56 commented Jan 28, 2025

I can have only 100 items in trakt collection? that's absurd!

Looks like this is the end of this project.

I agree.
I have to disable the plex_to_trakt: collection setting for now to make PTS work without error.
But Trakt CEO could change his mind if users complain enough.
He already did it in 2022 about personal lists.

The code still probably needs to get updated so it doesn't retry upon receiving 420 error message and probably mention a warning somewhere about the collection being limited to only 100 items.

I agree too.

@erikt311
Copy link

erikt311 commented Feb 1, 2025

Even if collections and watchlists and such are now limited on the Trakt end and I have to turn them off, as far as I am aware this project is still the only viable free way to deal with scrobbling.

Obviously nobody is owed anything and passion projects are subject to the whims of the passionate, but I'm sure hoping this piece at least continues to be maintained.

At least until Trakt breaks that, too.

@glensc
Copy link
Collaborator

glensc commented Feb 3, 2025

Can someone describe what would the behavior of AccountLimitExceeded be? The only action to take is IMHO to exit program. as doing anything else (continuing or retrying) will get you rate limited and maybe even blocked, which is not good at all

Saved my draft here:

@simonc56
Copy link
Collaborator

simonc56 commented Feb 3, 2025

Hitting the limit on a list doesn't mean you can't move on to toggle watched status of other items or add/remove items in other lists.

Suggestion : When AccountLimitExceeded on a list, just stop POSTing to that list (kind of blacklist the list until end of current sync) and move on to next sync action.

@blazer380
Copy link

For me it's not a collection issue. Nothing is updating on Trakt since this started happening.

@purplescorpion1
Copy link
Author

I disabled plex_to_trakt: collection setting and it runs without error and everything I have watched still syncs

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

6 participants