Choose server in a loop
Do not exit the loop until result is validated
MODIFY
plex_trakt_sync/commands/plex_login.py
plex_trakt_sync/commands/plex_login.py
+from http.client import RemoteDisconnected
from typing import List
import click
from plexapi.exceptions import Unauthorized
from plexapi.myplex import MyPlexAccount, MyPlexResource
from plexapi.server import PlexServer
+from urllib3.exceptions import ConnectTimeoutError
from plex_trakt_sync.config import CONFIG
@@ -78,7 +80,7 @@ def fmt_server(s):
)
-def choose_server(account: MyPlexAccount):
+def pick_server(account: MyPlexAccount):
servers = account.resources()
if not servers:
return None
@@ -96,6 +98,19 @@ def choose_server(account: MyPlexAccount):
return None
+def choose_server(account: MyPlexAccount):
+ while True:
+ try:
+ server = pick_server(account)
+ # Connect to obtain baseUrl
+ plex = server.connect()
+ # Validate connection again, the way we connect
+ plex = PlexServer(token=server.accessToken, baseurl=plex._baseurl)
+ return [server, plex]
+ except (ConnectTimeoutError, RemoteDisconnected, Exception) as e:
+ click.secho(f"{e}, Try another server, {type(e)}")
+
+
@click.command()
@click.option("--username", help="Plex login", default=CONFIG["PLEX_USERNAME"])
@click.option("--password", help="Plex password")

Choose server in a loop

Do not exit the loop until result is validated