Skip to content

Unable to connect to a Plex HTPC client #1292

Description

@mainTAP

Describe the Bug

When connecting to a HTPC (windows,1.50.1.4014) client, the API cannot connect properly as it retrieves its IP as 127.0.0.1 instead of its real IP. Other clients like Plexamp or Plex for mac work fine.

Code Snippets

>>>importplexapi>>>fromplexapi.serverimportPlexServer>>>baseurl='http://SERVERIP:32400'>>>plex=PlexServer(baseurl)
>>>client=plex.client("HTPC")
>>>print(client)
<PlexClient:http://127.0.0.1:324:HTPC>>>>client.timelineTraceback (mostrecentcalllast):
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/urllib3/connection.py", line203, in_new_connsock=connection.create_connection(
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/urllib3/util/connection.py", line85, increate_connectionraiseerrFile"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/urllib3/util/connection.py", line73, increate_connectionsock.connect(sa)
ConnectionRefusedError: [Errno111] ConnectionrefusedTheaboveexceptionwasthedirectcauseofthefollowingexception:
Traceback (mostrecentcalllast):
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line790, inurlopenresponse=self._make_request(
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line496, in_make_requestconn.request(
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/urllib3/connection.py", line395, inrequestself.endheaders()
File"/usr/lib/python3.9/http/client.py", line1250, inendheadersself._send_output(message_body, encode_chunked=encode_chunked)
File"/usr/lib/python3.9/http/client.py", line1010, in_send_outputself.send(msg)
File"/usr/lib/python3.9/http/client.py", line950, insendself.connect()
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/urllib3/connection.py", line243, inconnectself.sock=self._new_conn()
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/urllib3/connection.py", line218, in_new_connraiseNewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnectionobjectat0x75e15988>: Failedtoestablishanewconnection: [Errno111] ConnectionrefusedTheaboveexceptionwasthedirectcauseofthefollowingexception:
Traceback (mostrecentcalllast):
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/requests/adapters.py", line486, insendresp=conn.urlopen(
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line844, inurlopenretries=retries.increment(
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/urllib3/util/retry.py", line515, inincrementraiseMaxRetryError(_pool, url, reason) fromreason# type: ignore[arg-type]urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=32400): Maxretriesexceededwithurl: /player/timeline/poll?commandID=1&wait=0 (CausedbyNewConnectionError('<urllib3.connection.HTTPConnection object at 0x75e15988>: Failed to establish a new connection: [Errno 111] Connection refused'))
Duringhandlingoftheaboveexception, anotherexceptionoccurred:
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/plexapi/client.py", line587, intimelinereturnnext((xforxinself.timelines() ifx.state!='stopped'), None)
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/plexapi/client.py", line579, intimelinestimelines=self.sendCommand(ClientTimeline.key, wait=wait) or []
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/plexapi/client.py", line234, insendCommandreturnquery(key, headers=headers)
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/plexapi/client.py", line186, inqueryresponse=method(url, headers=headers, timeout=timeout, **kwargs)
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/requests/sessions.py", line602, ingetreturnself.request("GET", url, **kwargs)
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/requests/sessions.py", line589, inrequestresp=self.send(prep, **send_kwargs)
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/requests/sessions.py", line703, insendr=adapter.send(request, **kwargs)
File"/home/osmc/Scripts/audio-automation/venv/lib/python3.9/site-packages/requests/adapters.py", line519, insendraiseConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=32400): Maxretriesexceededwithurl: /player/timeline/poll?commandID=1&wait=0 (CausedbyNewConnectionError('<urllib3.connection.HTTPConnection object at 0x75e15988>: Failed to establish a new connection: [Errno 111] Connection refused'))
>>>

Expected Behavior

To be able to connect to HTPC client and control it

Additional Context

Retrieving the clients from the server via SERVERIP:32400/clients shows the HTPC twice, once with 127.0.0.1 and also one with IP of the server ( rather than the IP of the actual client ).
If I iterate over the plex.clients() and use the instance with the server's IP address, I'm able to retrieve the timeline but can't control the client like client.pause() and get timeout error :
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='SERVERIP', port=32400): Read timed out. (read timeout=30)

Operating System and Version

Debian ( PlexAPI ) , Ubuntu ( Plex Server ) , Windows 11 ( Plex HTPC )

Plex Media Server Version

1.32.7.7621

Python Version

3.9.2

PlexAPI Version

4.15.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions