Skip to content

Commit 003f02c

Browse files
authored
Pass session from MyPlexAccount to server/device connection (#1163)
1 parent 09d1d30 commit 003f02c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

plexapi/myplex.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ def connect(
14221422
# Try connecting to all known resource connections in parallel, but
14231423
# only return the first server (in order) that provides a response.
14241424
cls = PlexServer if 'server' in self.provides else PlexClient
1425-
listargs = [[cls, url, self.accessToken, timeout] for url in connections]
1425+
listargs = [[cls, url, self.accessToken, self._server._session, timeout] for url in connections]
14261426
log.debug('Testing %s resource connections..', len(listargs))
14271427
results = utils.threaded(_connect, listargs)
14281428
return _chooseConnection('Resource', self.name, results)
@@ -1517,7 +1517,7 @@ def connect(self, timeout=None):
15171517
:exc:`~plexapi.exceptions.NotFound`: When unable to connect to any addresses for this device.
15181518
"""
15191519
cls = PlexServer if 'server' in self.provides else PlexClient
1520-
listargs = [[cls, url, self.token, timeout] for url in self.connections]
1520+
listargs = [[cls, url, self.token, self._server._session, timeout] for url in self.connections]
15211521
log.debug('Testing %s device connections..', len(listargs))
15221522
results = utils.threaded(_connect, listargs)
15231523
return _chooseConnection('Device', self.name, results)
@@ -1767,14 +1767,15 @@ def _query(self, url, method=None, headers=None, **kwargs):
17671767
return ElementTree.fromstring(data) if data.strip() else None
17681768

17691769

1770-
def _connect(cls, url, token, timeout, results, i, job_is_done_event=None):
1770+
def _connect(cls, url, token, session, timeout, results, i, job_is_done_event=None):
17711771
""" Connects to the specified cls with url and token. Stores the connection
17721772
information to results[i] in a threadsafe way.
17731773
17741774
Arguments:
17751775
cls: the class which is responsible for establishing connection, basically it's
17761776
:class:`~plexapi.client.PlexClient` or :class:`~plexapi.server.PlexServer`
17771777
url (str): url which should be passed as `baseurl` argument to cls.__init__()
1778+
session (requests.Session): session which sould be passed as `session` argument to cls.__init()
17781779
token (str): authentication token which should be passed as `baseurl` argument to cls.__init__()
17791780
timeout (int): timeout which should be passed as `baseurl` argument to cls.__init__()
17801781
results (list): pre-filled list for results
@@ -1784,7 +1785,7 @@ def _connect(cls, url, token, timeout, results, i, job_is_done_event=None):
17841785
"""
17851786
starttime = time.time()
17861787
try:
1787-
device = cls(baseurl=url, token=token, timeout=timeout)
1788+
device = cls(baseurl=url, token=token, session=session, timeout=timeout)
17881789
runtime = int(time.time() - starttime)
17891790
results[i] = (url, token, device, runtime)
17901791
if X_PLEX_ENABLE_FAST_CONNECT and job_is_done_event:

tools/plex-listtokens.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _list_devices(account, servers):
4747
def _test_servers(servers):
4848
items, seen = [], set()
4949
print('Finding Plex clients..')
50-
listargs = [[PlexServer, s, t, 5] for s,t in servers.items()]
50+
listargs = [[PlexServer, s, t, None, 5] for s,t in servers.items()]
5151
results = utils.threaded(_connect, listargs)
5252
for url, token, plex, runtime in results:
5353
clients = plex.clients() if plex else []

0 commit comments

Comments
 (0)