Set PlexServer session to value we control
MODIFY
plex_trakt_sync/plex_server.py
plex_trakt_sync/plex_server.py
+from functools import partial
+
import plexapi.server
+
from plex_trakt_sync.config import PLEX_PLATFORM
from plex_trakt_sync.decorators.nocache import nocache
from plex_trakt_sync.factory import factory
@@ -27,13 +30,16 @@ def _get_plex_server():
plexapi.X_PLEX_PLATFORM = PLEX_PLATFORM
plexapi.BASE_HEADERS['X-Plex-Platform'] = plexapi.X_PLEX_PLATFORM
+ session = factory.session()
+ PlexServer = partial(plexapi.server.PlexServer, session=session)
+
# if connection fails, it will try :
# 1. url expected by new ssl certificate
# 2. url without ssl
# 3. fallback url (localhost)
+
try:
- server = plexapi.server.PlexServer(
- token=plex_token, baseurl=plex_baseurl)
+ server = PlexServer(token=plex_token, baseurl=plex_baseurl)
except plexapi.server.requests.exceptions.SSLError as e:
m = "Plex connection error: {}, fallback url {} didn't respond either.".format(str(e), plex_fallbackurl)
excep_msg = str(e.__context__)
@@ -43,8 +49,7 @@ def _get_plex_server():
end_pos = plex_baseurl.find(".plex.direct")
new_plex_baseurl = plex_baseurl[:end_pos - 32] + new_hash + plex_baseurl[end_pos:]
try: # 1
- server = plexapi.server.PlexServer(
- token=plex_token, baseurl=new_plex_baseurl)
+ server = PlexServer(token=plex_token, baseurl=new_plex_baseurl)
# save new url to .env
CONFIG["PLEX_TOKEN"] = plex_token
CONFIG["PLEX_BASEURL"] = new_plex_baseurl
@@ -56,8 +61,7 @@ def _get_plex_server():
if server is None and plex_baseurl[:5] == "https":
new_plex_baseurl = plex_baseurl.replace("https", "http")
try: # 2
- server = plexapi.server.PlexServer(
- token=plex_token, baseurl=new_plex_baseurl)
+ server = PlexServer(token=plex_token, baseurl=new_plex_baseurl)
logger.warning("Switched to Plex unsecure connection because of SSLError.")
except Exception:
pass
@@ -66,8 +70,7 @@ def _get_plex_server():
pass
if server is None:
try: # 3
- server = plexapi.server.PlexServer(
- token=plex_token, baseurl=plex_fallbackurl)
+ server = PlexServer(token=plex_token, baseurl=plex_fallbackurl)
logger.warning("No response from {}, fallback to {}".format(plex_baseurl, plex_fallbackurl))
except Exception:
logger.error(m)

Set PlexServer session to value we control