trakt / Plex-Trakt-Scrobbler

Add what you are watching on Plex to trakt.tv
1.44k stars 167 forks source link

Unable to sync [Unable to retrieve account details from plex.tv] #611

Open arabcoders opened 2 years ago

arabcoders commented 2 years ago

Hello,

Syncing from plex stopped few days ago, while still working in jellyfin. i searched the logs and it seems for reason the plugin is unable to get the plex account.

2021-10-06 14:45:34,284 - plugin.models.m_plex.account     (7fcf495dab38) :  INFO (plugin.models.m_plex.account:118) - Refreshing plex account: <PlexAccount username: u'my-username'>
2021-10-06 14:45:34,798 - plugin.models.m_plex.account     (7fcf495dab38) :  WARNING (plugin.models.m_plex.account:126) - Unable to retrieve account details from plex.tv (status_code: 422)

and this message kept on being repeated every time the server tries to sync.

[17 minutes ago] AccountAuthenticationError: Plex account is missing the server token

things 1 did.

  1. remove every trace of the plugin and reinstall. - failed same issue
  2. disclaim the server and reclaim. - nope same issue
  3. re-authorize the plugin via trakt.tv.
arabcoders commented 2 years ago

The easy way

download the fork from https://github.com/Cornishman/Plex-Trakt-Scrobbler/tree/scrobble_fix_with_PlexOnlineToken_fix to fix the issue.

The hard way

Ok for some reason this issue has blown up and there is lots of requests on how to do this thing. I'll try to gather the information in easy to consume way. The temp fix involve editing file in traktv.bundle directory.

X-Plex-Token

First step is to get your X-Plex-Token. For how to find it please visit this link. https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/

File Location

The file location depends on how you installed plex.

On regular installation please refers to this page to find Plex data directory. https://support.plex.tv/articles/202915258-where-is-the-plex-media-server-data-directory-located/

Synology

on "Synology package" The files located in the Plex shared folder. Open File station and go to "Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/modules/migrations/account.py" via @coreyp93

Others

In General you need to edit this file "Trakttv.bundle/Contents/Libraries/Shared/plugin/modules/migrations/account.py"

Editing the File

around line 241 look for

env_token = os.environ.get('PLEXTOKEN')

There is two ways you can fix this issue if you know what environment variable is choose option 2, if you dont understand what is environment variable is choose option 1.

Change the line to

Option 1

        #env_token = os.environ.get('PLEXTOKEN')
        env_token = 'Your X-Plex-Token here'

Option 2

        #env_token = os.environ.get('PLEXTOKEN')
        env_token = os.environ.get('PLEX_SERVER_TOKEN')

be mindful that python uses whitespace as indentation level, so make sure replaced code matches the indentation level. via @regystro

add PLEX_SERVER_TOKEN with your X-Plex-Token as value. in whatever system or container you use. i.e. unraid custom ENV Vars or windows or docker-compose, or whatever system you use.

finally

After editing the file and making sure the changes saved. restart plex.

Gandrushka commented 2 years ago

i have the same issue, but this did't helped me. maybe because i don't use docker

arabcoders commented 2 years ago

i have the same issue, but this did't helped me. maybe because i don't use docker

I use docker mostly, but i think you can do same steps and instead of editing docker-compose.yaml do export PLEX_SERVER_TOKEN=YOUR_PLEX_TOKEN in shell that runs plex and then restart the plex process. if you can describe how you are running PMS i may be able to help. if it's windows you have to add ENV globally and restart the PMS process.

or you can just hardcode the token

so instead of

#env_token = os.environ.get('PLEXTOKEN')
env_token = os.environ.get('PLEX_SERVER_TOKEN')

you do

#env_token = os.environ.get('PLEXTOKEN')
env_token = 'YOUR-PLEX-TOKEN'

PS, i dont recommend hardcoding the token into the code, but it's a quick work around until the plugin is updated.

Gandrushka commented 2 years ago

So i tried to hardcode the token, no result at all - it just deletes the Trakt plugin from unofficial appstore

Tried to leave it as is after reinstall - now only movies sync with Trakt - both play status and watched. As for shows - nothing: no playing status, no scrobbling.

Gandrushka commented 2 years ago

The workaround for shows is simple - use original titles. I used translated ones, but it didn't worked for me. And with original titles everything works

pochacho99 commented 2 years ago

The workaround for shows is simple - use original titles. I used translated ones, but it didn't worked for me. And with original titles everything works

I am having this problem also, just suddenly stopped working, getting error message "Plex account is missing the server token". @Gandrushka by original titles, do you mean the English titles? There is an option in the TV Series Agent to choose Original Titles, but this returns movies and shows in their native language (same as your translated above?)?

arabcoders commented 2 years ago

The workaround for shows is simple - use original titles. I used translated ones, but it didn't worked for me. And with original titles everything works

I am having this problem also, just suddenly stopped working, getting error message "Plex account is missing the server token". @Gandrushka by original titles, do you mean the English titles? There is an option in the TV Series Agent to choose Original Titles, but this returns movies and shows in their native language (same as your translated above?)?

I Don't think @Gandrushka problem is the same as me or you. so you can try the fix i posted it may help.

Gandrushka commented 2 years ago

but this returns movies and shows in their native language

yep, that what i thought for the first time. but then i tried it with "Squid game", episodes and series names changed to Korean and Trakt seems to not see it again.

So my theory about original titles was wrong, now I'm using English for the library language and Trakt works

JBeresford commented 2 years ago

I was able to do temp fix until there there is an official way.

Open  File "Application Support/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/modules/migrations/account.py"

around line 241 look for

env_token = os.environ.get('PLEXTOKEN')

Change the line to

#env_token = os.environ.get('PLEXTOKEN')
env_token = os.environ.get('PLEX_SERVER_TOKEN')

Add

PLEX_SERVER_TOKEN=YOUR_PLEX_TOKEN 

in your docker-compose.yaml

save than restart plex container. 

For some reason Plex is not giving the correct token in "PLEXTOKEN" ENV it was giving something like local-GUID token which is failing to authenticate against the API.

after doing this fix, i was able to to both push and pull updates.

I suspect that this was introduced in Plex version: 1.24.4.5081 - as following me updating to this version this morning on my Windows machine I ran into the same issue as described. I've done a search through all the Plex files and there doesn't seem to be anywhere in plain text they set that variable (they read from it a few times), they must be assigning it at runtime from a compiled file.

Can confirm that changing the environment variable check in the plugin resolved this for me too

abiacco commented 2 years ago

I'm running 5081 beta also on my test/backup server where this is happening (i pull watched statuses from my prod server which is pushing statuses fine on 5033). I put the plex token in /etc/systemd/system/plexmediaserver.service.d/override.conf as Environment="PLEXTOKEN=<token>" and that allowed me to do a pull ok for now. I just run the .deb version

Skyline404 commented 2 years ago

I was able to do temp fix until there there is an official way.

Open  File "Application Support/Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/modules/migrations/account.py"

around line 241 look for

env_token = os.environ.get('PLEXTOKEN')

Change the line to

#env_token = os.environ.get('PLEXTOKEN')
env_token = os.environ.get('PLEX_SERVER_TOKEN')

Add

PLEX_SERVER_TOKEN=YOUR_PLEX_TOKEN 

in your docker-compose.yaml

save than restart plex container. 

For some reason Plex is not giving the correct token in "PLEXTOKEN" ENV it was giving something like local-GUID token which is failing to authenticate against the API.

after doing this fix, i was able to to both push and pull updates.

Great fix, thx !

pochacho99 commented 2 years ago

The workaround for shows is simple - use original titles. I used translated ones, but it didn't worked for me. And with original titles everything works

I am having this problem also, just suddenly stopped working, getting error message "Plex account is missing the server token". @Gandrushka by original titles, do you mean the English titles? There is an option in the TV Series Agent to choose Original Titles, but this returns movies and shows in their native language (same as your translated above?)?

I Don't think @Gandrushka problem is the same as me or you. so you can try the fix i posted it may help.

Thanks, this fix works! Hope the plugin will be updated soon.

sickyd commented 2 years ago

Cheers, changing the environment variable and line in the code worked on Windows PMS setup.

rg9400 commented 2 years ago

Can someone confirm exactly which features are broken with this change? The devs have indicated that this was intentional and the token now being exposed is valid, it just can't be used via the API that is being leveraged by the plugin (have to use PMS API directly instead).

I seem to still be able to scrobble and push playback progress fine. So is the issue pulling data? Doing full syncs? Lists or collections?

TobiasRuano commented 2 years ago

@rg9400 for me it was completly broken. Nothing worked. No scrobble, collection (push), ratings (pull, push), watch status (pull, push).

Setting the ENV solve all this.

arabcoders commented 2 years ago

@rg9400 for me it was completly broken. Nothing worked. No scrobble, collection (push), ratings (pull, push), watch status (pull, push).

Setting the ENV solve all this.

likewise the plugin was completely broken with the messages i attached. for some weird reason sometimes it works for few days then it would stop working and give this random local-guid token with ofc cant cant be used with plex api for some reason.

olliebean commented 2 years ago

I'm seeing the same error in the logs ("Plex account is missing the server token"), but automatic syncing and scrobbling still seem to be working fine. The only reason I realised there was a problem was because I tried to access the plugin via Kitana to do a manual sync.

bakes82 commented 2 years ago

Can someone confirm exactly which features are broken with this change? The devs have indicated that this was intentional and the token now being exposed is valid, it just can't be used via the API that is being leveraged by the plugin (have to use PMS API directly instead).

I seem to still be able to scrobble and push playback progress fine. So is the issue pulling data? Doing full syncs? Lists or collections?

It seems like even though there is an error its works until you prob install new version or something. Mine was working with error until an update. Hard coding the plex token worked.

rg9400 commented 2 years ago

yeah mine broke today as well. But now here's the issue. Using the PMS API is not a small change AFAIK, and grabbing the token in some other automated fashion also looks like it will be complicated. Anyone have any ideas for a proper fix? Because it's beyond me. This method works but is not ideal.

arabcoders commented 2 years ago

yeah mine broke today as well. But now here's the issue. Using the PMS API is not a small change AFAIK, and grabbing the token in some other automated fashion also looks like it will be complicated. Anyone have any ideas for a proper fix? Because it's beyond me. This method works but is not ideal.

Honestly, if possible just add a new field in settings for plex token and continue as usual. until you feel like rewriting the plugin to use the PMS API.

olliebean commented 2 years ago

Perhaps someone could explain how to get the plex token? I found two methods on the Plex website: one (https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/) is by reading the xml of a library item, but this page says the token is "valid temporarily," and presumably we need one that is valid permanently. The other (https://forums.plex.tv/t/authenticating-with-plex/609370) is a complicated explanation of how a 3rd party app (or presumably a plugin such as this one) could get the token, but this doesn't seem to be a method that an end user can easily use.

OttoWerse commented 2 years ago

For me personally, removing all authetification from the first account/home user in the plugin configuration, and then adding the previously used plex and trakt auth to a new user is currently a good workaround. It's not pretty, but it works so far.

So far I have only had issues on the first (undeletable) user, all my home users have had absolutley no syncing issues over the past few months, as it turns out. So just do not use the default plugin user at all to avoid errors I would say.

olliebean commented 2 years ago

For me personally, removing all authetification from the first account/home user in the plugin configuration, and then adding the previously used plex and trakt auth to a new user is currently a good workaround. It's not pretty, but it works so far.

How do I do that? I only have one user; I tried adding another, but I couldn't see any options in the plugin configuration to set different details for a different user, and when I switched to the new user I couldn't access the plugin configuration settings at all.

OttoWerse commented 2 years ago

For me personally, removing all authetification from the first account/home user in the plugin configuration, and then adding the previously used plex and trakt auth to a new user is currently a good workaround. It's not pretty, but it works so far.

How do I do that? I only have one user; I tried adding another, but I couldn't see any options in the plugin configuration to set different details for a different user, and when I switched to the new user I couldn't access the plugin configuration settings at all.

You need to set the mapping first, so that each user will be mapped to their corresponding Trakt account: https://github.com/trakt/Plex-Trakt-Scrobbler/wiki/FAQ---Scrobbling

Configuration does not happen inside of Plex Plugins for other users (only the main, undeletable one, which has always been buggy) you have to do it in the Configuration of the Plugin under "Accounts".

olliebean commented 2 years ago

In the absence of a step-by-step guide, I think I'd better leave well alone for now and hope the plugin gets updated with a fix for this issue before it stops working entirely for me. Absolutely no idea what I'm supposed to be doing on that configuration page.

arabcoders commented 2 years ago

Perhaps someone could explain how to get the plex token? I found two methods on the Plex website: one (https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/) is by reading the xml of a library item, but this page says the token is "valid temporarily," and presumably we need one that is valid permanently. The other (https://forums.plex.tv/t/authenticating-with-plex/609370) is a complicated explanation of how a 3rd party app (or presumably a plugin such as this one) could get the token, but this doesn't seem to be a method that an end user can easily use.

I didn't notice the plex token changing, unless i disclaim the server and re-claim it. so you can follow the steps i posted to fix it even if plex token is temporary.

djnield commented 2 years ago

For me personally, removing all authetification from the first account/home user in the plugin configuration, and then adding the previously used plex and trakt auth to a new user is currently a good workaround. It's not pretty, but it works so far.

So far I have only had issues on the first (undeletable) user, all my home users have had absolutley no syncing issues over the past few months, as it turns out. So just do not use the default plugin user at all to avoid errors I would say.

Think I understood about creating a second user and using that over the default..

Just clarify, after doing this, does the settings in the plex app still need to have a pin set?

oliverjhyde commented 2 years ago

I tried the hardcoding the key but that just caused the plugin to not show in settings or Kitana so I undid that. Going here and disconnecting and reconnecting Plex has everything working again for me.

JourneyOver commented 2 years ago

Going here and disconnecting and reconnecting Plex has everything working again for me.

This is what worked for me as well.

Edit: Though it doesn't seem to be a long term fix, just temporary as it seems to eventually throw the Error Plex account is missing the server token error again.

fr05ty-mc commented 2 years ago

Change the line to

env_token = os.environ.get('PLEXTOKEN')

env_token = os.environ.get('PLEX_SERVER_TOKEN')

Add

PLEX_SERVER_TOKEN=YOUR_PLEX_TOKEN

in your docker-compose.yaml

save than restart plex container.

hi I have been looking for a fix for a few days now and came across this, PLEX will send what I have watched to Trakt.tv, I had manually marked a show as watched but it never pulled the status from trakt, I also noticed it was not adding new shows to collected.

I then found about kitana.bas.sh logged in and found the error message, which leads me here, my plex server runs on unraid I have found the account.py file and where to edit it, but where abouts do I find the second part to edit/add? do i add a new path/variable to the container, any help would be appreciated, and I'm guessing 'your_plex_token' is actually meant to be replaced with my token

arabcoders commented 2 years ago

Change the line to

env_token = os.environ.get('PLEXTOKEN')

env_token = os.environ.get('PLEX_SERVER_TOKEN')

Add

PLEX_SERVER_TOKEN=YOUR_PLEX_TOKEN

in your docker-compose.yaml

save than restart plex container.

hi I have been looking for a fix for a few days now and came across this, PLEX will send what I have watched to Trakt.tv, I had manually marked a show as watched but it never pulled the status from trakt, I also noticed it was not adding new shows to collected.

I then found about kitana.bas.sh logged in and found the error message, which leads me here, my plex server runs on unraid I have found the account.py file and where to edit it, but where abouts do I find the second part to edit/add? do i add a new path/variable to the container, any help would be appreciated, and I'm guessing 'your_plex_token' is actually meant to be replaced with my token

Sorry I'm not familiar with unraid, i assume it has a page where you can add environment variables to a container. if not you can hardcode the token directly into the file.

fr05ty-mc commented 2 years ago

all good i have it up and running again, thanks for the info

for anyone else that comes looking, in unraid web gui >docker tab > click your plex container name> at the bottom of the plex config page click +add another path, variable, port...., in the pop up change drop down to variable, paste PLEX_SERVER_TOKEN in to key field and your token into the value field , then click ADD when the pop up closes click APPLY let it rebuild and all good. just don't forget to modify the account.py file :)

dpons039 commented 2 years ago

I just motive that i'm getting the issue but in my case Plex is running as a Synology package so I can't just add the variable like on docker.

Any idea on how to add the token into the plugin? even if it's harcoded?

Thanks

coreyp93 commented 2 years ago

I just motive that i'm getting the issue but in my case Plex is running as a Synology package so I can't just add the variable like on docker.

Any idea on how to add the token into the plugin? even if it's harcoded?

Thanks

It's exactly the same, the files located in the Plex shared folder. Open File station and go to "Plex Media Server/Plug-ins/Trakttv.bundle/Contents/Libraries/Shared/plugin/modules/migrations/account.py"

around line 241 look for

env_token = os.environ.get('PLEXTOKEN')

Change the line to

env_token = os.environ.get('PLEXTOKEN')

env_token = 'PLEX_SERVER_TOKEN'

And restart plex.

Alternatively you could use this and log in to plex which refreshes the token; https://trakt-for-plex.github.io/configuration/#/login

heezy01 commented 2 years ago

where can i find my, 'PLEX_SERVER_TOKEN'? is it the same as the, 'X-Plex-Token' in the media XML files?

scoiattolo49 commented 2 years ago

where can i find my, 'PLEX_SERVER_TOKEN'? is it the same as the, 'X-Plex-Token' in the media XML files?

Yes it is.

https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/

arabcoders commented 2 years ago

I Update 2nd post to include most asked information, please refers to it until the maintainer fixes this issue.

https://github.com/trakt/Plex-Trakt-Scrobbler/issues/611#issuecomment-936738723

hapklaar commented 2 years ago

For some reason this doesn't work for me. I tried the system variable route and now the hardcoded route, but trakt keeps complaining in logs about missing the server token when I initiate a sync from Kitana after restarting Plex: 200 GET /video/trakt/sync?account_id=1&title=Error&message_only=True&message=Plex+account+is+missing+the+server+token (127.0.0.1) 7.35ms

I changed the specified account.py as follows: image

What am I missing?

regystro commented 2 years ago

What am I missing?

Wrong indentation. The commented out line below # Environment token should start at the same level. Also beware of your editor, it might be using spaces or tabs for indentation. You must use the same that account.py uses.

hapklaar commented 2 years ago

What am I missing?

Wrong indentation. The commented out line below # Environment token should start at the same level. Also beware of your editor, it might be using spaces or tabs for indentation. You must use the same that account.py uses.

I wasn't aware python was so particular about indentation. Replacing the tabs I used, for spaces which are used in account.py and adding a space before the commented out line seems to have fixed it.

Thanks.

Jellyfrog commented 2 years ago

Ive replaced the token, and also tried by adding a second account under http://trakt-for-plex.github.io/configuration/#/configuration/accounts, this makes the scrobbler function work, but I'm unable to sync watched status. Does anyway expire the same issue? In the logs I can see it downloads my trakt history etc, but it doesn't work. Is it related to the new plex scanner/agents?

arabcoders commented 2 years ago

Ive replaced the token, and also tried by adding a second account under http://trakt-for-plex.github.io/configuration/#/configuration/accounts, this makes the scrobbler function work, but I'm unable to sync watched status. Does anyway expire the same issue? In the logs I can see it downloads my trakt history etc, but it doesn't work. Is it related to the new plex scanner/agents?

not sure this is related to the issue we are facing, you may want to use kitana to force overall push https://github.com/pannal/Kitana

leeaash commented 2 years ago

Waiting for an update on the plugin to fix the issue? Or waiting for the plex new update to resolve that? what can i do now?

arabcoders commented 2 years ago

Waiting for an update on the plugin to fix the issue? Or waiting for the plex new update to resolve that? what can i do now?

from what @rg9400 said i don't think plex intend to fix this problem, and the maintainer has to update the plugin to work with the new API. and it's difficult to do so, so my suggestion still stands adding a new config field for X-Plex-Token in the plugin config until such time the maintainer has time to upgrade to the new API.

As for what you can do right now, you can temporality get the plugin to work using the methods i posted in comment-#2

an3k commented 2 years ago

https://github.com/trakt/Plex-Trakt-Scrobbler/issues/611#issuecomment-936738723 Didn't solved the issue for me. Tried it with both options.

Whenever I authenticate my Plex account at https://trakt-for-plex.github.io/configuration/#/configuration/accounts the little gray icon turned green. This doesn't happen anymore. I tried a lot here and there and in the end I thought about removing the authentication for my trakt account. I did so and after trying to re-authenticate the trakt account the icon for this doesn't turn green either.

I removed the whole thing, installed it again and without any modification it works again.

an3k commented 2 years ago

Celebrated too early. I get no error message but success messages, however there is no syncing done, neither my collection gets updates nor ratings and scrobbling doesn't work too.

fent commented 2 years ago

for me, since I'm using unraid, I needed to add the plex token to the container env as well

blindguy commented 2 years ago

I was able to get new items I watch on plex to be marked at trakt.tv but I can't pull down all my watched status from trakt.tv, any thoughts on how to force the pull or to sync from them?

arabcoders commented 2 years ago

I was able to get new items I watch on plex to be marked at trakt.tv but I can't pull down all my watched status from trakt.tv, any thoughts on how to force the pull or to sync from them?

it wont pull old items you have to use kitana to force pull and push.

blindguy commented 2 years ago

I was able to get new items I watch on plex to be marked at trakt.tv but I can't pull down all my watched status from trakt.tv, any thoughts on how to force the pull or to sync from them?

it wont pull old items you have to use kitana to force pull and push.

thanks for the note! I took a look at this https://github.com/pannal/Kitana - is that the kitana you are talking about?