mstinaff / PMS_Updater

Shell script for updating the Plex Media Server inside the FreeNAS Plex plugin
MIT License
442 stars 90 forks source link

ImportError: No module named site #57

Closed Blackcatz1911 closed 1 year ago

Blackcatz1911 commented 3 years ago

Current error running on 12.1-RELEASE-p13:

Using URL https://plex.tv/api/downloads/5.json
Searching https://plex.tv/api/downloads/5.json for the FreeBSD download URL .....
ImportError: No module named site
Could not find a FreeBSD download link on page https://plex.tv/api/downloads/5.json?channel=plexpass&X-Plex-Token=...
scarygary commented 3 years ago

Didn't work for me. I've had to manually upgrade the three last releases. Currently running PMS 1.23.0.4482 in a 12.2-RELEASE-p6 jail on TrueNAS-12.0-U3. root@plex:~ # ./PMS_Updater.sh -vv -a Using URL https://plex.tv/api/downloads/5.json Searching https://plex.tv/api/downloads/5.json for the FreeBSD download URL .....ImportError: No module named site Could not find a FreeBSD download link on page https://plex.tv/api/downloads/5.json?channel=plexpass&X-Plex-Token=XXXXXXXXXXXXXXXXX root@plex:~ #

JonnyWong16 commented 3 years ago

I made a change to use jq instead of the Plex bundled Python to parse the json for the download URL. Unfortunately, this is an extra external dependency.

Temporary workaround:

  1. Run pkg install jq to install jq.
  2. Change the DOWNLOADURL on line 135 to:
    DOWNLOADURL="$(fetch -q $TOKENURL -o- | jq -r '.computer.FreeBSD.releases[0].url')"
scarygary commented 3 years ago

I installed an older version of PMS and checked /usr/local/share/plexmediaserver-plexpass/Resources/Python/lib/python2.7. It contains all the necessary modules. On PMS 1.23.0.4497 and I'm guessing a few versions back, that folder is pretty much empty, except for a subfolder called site-packages. I wonder why all the modules were removed?

scarygary commented 3 years ago

This is the reply I got over at the plex forums: _In 1.23 we changed how our script host is distributed. The standard library is now in python27.zip. If you want to run it from the command line you need to point the environment variable PYTHONPATH to the python27.zip file.

I wouldn’t rely on using the plex script host outside plugins in PMS though. We don’t consider any other usage and might change or remove functionality as we see fit. So you have been warned._

I tried adding python27.zip to the end of the export PYTHONHOME so now it reads export PYTHONHOME="$PMSPARENTPATH/$PMSLIVEFOLDER/Resources/Python/python27.zip"

It still doesn't work though. Same error message as before. No idea why.

ZoltrixGFC commented 3 years ago

@scarygary you mention you have upgraded manually recently. Is that a pretty straightforward process?

jbeez commented 3 years ago

I just "fixed" this in my fork.

https://github.com/jbeez/PMS_Updater/blob/TokenAuth/PMS_Updater.sh

jbeez commented 3 years ago

I ran into the environment issues you guys did, my fix was to ln -s the python27.zip file into the same directory as the Plex Script Host binary, I'm not sure why its not respecting my PYTHONHOME OR PYTHONPATH variables in the script. the sys.path variable in python typicaly will look for this zip file with the site module in the directory of the python binary and im exploiting that fact with the small fix i did.

It checks for existance of the symlink, if not there it links it. Then proceeds, if it does an install, it will link it after it rolls out the new version for you at install time, so its there for the next time the script needs to launch.

JonnyWong16 commented 3 years ago

All we need to do is add the following at L216

export PYTHONPATH="$PYTHONHOME/python27.zip"
jbeez commented 3 years ago

Thank you! I was trying to define that differently and it just wasn't working for me.

jarodwsams commented 3 years ago

@JonnyWong16's fix worked for me, as well.

chrispinkney commented 3 years ago

@jbeez Thank you!

afettouhi commented 3 years ago

@jbeez

I just tried your fork of the PMS_Updater script and I get this error:

./PMS_Updater.sh 7: Syntax error: newline unexpected (expecting word)

jbeez commented 3 years ago

@afettouhi ty I'll take a look. Are you in the Plex plug-in jail, or did you do a normal jail and install Plex manually?

Pretty sure I used fetch to pull it right from GitHub to test in my plug-in jail, if you didn't can you try that, maybe download corrupted somehow(weird)

afettouhi commented 3 years ago

@jbeez normal jail and install of Plex afterwards.

mikethecalamity commented 3 years ago

@jbeez When I use the script with these fixes, my server gets messed up and I can't access the settings anymore (see below). I am using the script with -n and fixed the Preferences.xml path for /usr/local/plexdata. Any ideas? image

afettouhi commented 3 years ago

@mweber03 I also have this issue with my Plex install.

jbeez commented 3 years ago

Is the common denominator here that you're all using the -n flag?

JonnyWong16 commented 3 years ago

That issue has nothing to do with the updater script.

https://www.reddit.com/r/PleX/comments/n3a8ob/server_settings_are_unavailable_truenas_iocage/

mikethecalamity commented 3 years ago

Thanks @JonnyWong16, I actually just used the script to downgrade to 1.22 with everything working and came to a similar conclusion that the script is not at fault.

I appreciate the link to the fixes for the actually problem, which did fix it for me.

@afettouhi TLDR, in /usr/local/etc/rc.d/plexmediaserver, add the following to the plex_precmd() block then restart the service:

export LD_LIBRARY_PATH="${SCRIPTPATH}/lib"
afettouhi commented 3 years ago

Thanks @JonnyWong16, I actually just used the script to downgrade to 1.22 with everything working and came to a similar conclusion that the script is not at fault.

I appreciate the link to the fixes for the actually problem, which did fix it for me.

@afettouhi TLDR, in /usr/local/etc/rc.d/plexmediaserver, add the following to the plex_precmd() block then restart the service:

export LD_LIBRARY_PATH="${SCRIPTPATH}/lib"

@mweber03 Got it. Added that extra line and I can now see the settings tab again. Still though my initial issue with the forked script remains.

jbeez commented 3 years ago

@afettouhi I just ran this and no syntax error, line 7 is just a LOGGING=1 statement, not sure why you're getting an error there.

root@plex:~ # fetch https://raw.githubusercontent.com/jbeez/PMS_Updater/TokenAuth/PMS_Updater.sh && chmod 700 PMS_Updater.sh PMS_Updater.sh 9265 B 48 MBps 00s root@plex:~ # ./PMS_Updater.sh Using URL https://plex.tv/api/downloads/5.json Searching https://plex.tv/api/downloads/5.json for the FreeBSD download URL .....Done. Already running latest version v1.23.2.4656-85f0adf5b

afettouhi commented 3 years ago

I just ran the commands you just listed with chmod 700 and now it works for me.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.