core: Plex integration: Connect to server using dynamic external IP -> fails after reconnect

The problem

When the Plex integration is setup using the option to get a new auth token from Plex a new tab with Plex sign-in is opened, sign-in works, but kick-back to HA doesn’t work because the URL used does not contain the HA port 8123 (so basic SSL 443 is used, where HA doesn’t listen in my and probably most cases) -> time-out. If I manually add the port to the URL it takes a couple of secons, then the integration with all devices and entities is successfully added.

During this process this happens:

2021-01-20 10:11:23 INFO (SyncWorker_8) [plexapi] Testing 6 resource connections..
2021-01-20 10:11:23 ERROR (Thread-266) [plexapi] http://172.104.130.172:8443: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
2021-01-20 10:11:23 ERROR (Thread-261) [plexapi] https://192-168-23-11.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct:32400: HTTPSConnectionPool(host='192-168-23-11.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct', port=32400): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0xffff9031dd00>: Failed to establish a new connection: [Errno -2] Name does not resolve'))
2021-01-20 10:11:25 INFO (SyncWorker_8) [plexapi] Resource connection ERR (0s): https://192-168-23-11.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct:32400?X-Plex-Token=<hidden>
2021-01-20 10:11:25 INFO (SyncWorker_8) [plexapi] Resource connection OK (1s): https://79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct:32400?X-Plex-Token=<hidden>
2021-01-20 10:11:25 INFO (SyncWorker_8) [plexapi] Resource connection OK (1s): https://172-104-130-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct:8443?X-Plex-Token=<hidden>
2021-01-20 10:11:25 INFO (SyncWorker_8) [plexapi] Resource connection OK (1s): http://192.168.23.11:32400?X-Plex-Token=<hidden>
2021-01-20 10:11:25 INFO (SyncWorker_8) [plexapi] Resource connection OK (1s): http://79.222.72.172:32400?X-Plex-Token=<hidden>
2021-01-20 10:11:25 INFO (SyncWorker_8) [plexapi] Resource connection ERR (0s): http://172.104.130.172:8443?X-Plex-Token=<hidden>
2021-01-20 10:11:25 INFO (SyncWorker_8) [plexapi] Connecting to Resource: https://79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct:32400?X-Plex-Token=<hidden>

The Plex servers internal IP is 192.168.23.11:32400, 79.222.72.172 is the current external IP which changes every 24hrs upon reconnect of the DSL connection.

Now the integration appears to chose the external IP for connection and everything seems to work fine. After the reconnect during the next night / morning this happens:

2021-01-21 05:47:29 ERROR (MainThread) [homeassistant.components.plex.server] Could not connect to Plex server: KSrv02 (HTTPSConnectionPool(host='79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct', port=32400): Max retries exceeded with url: /clients (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0xffff933f9580>, 'Connection to 79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct timed out. (connect timeout=30)')))
2021-01-21 05:48:44 ERROR (MainThread) [homeassistant.components.plex.server] Could not connect to Plex server: KSrv02 (HTTPSConnectionPool(host='79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct', port=32400): Max retries exceeded with url: /clients (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0xffff8fb33460>, 'Connection to 79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct timed out. (connect timeout=30)')))
2021-01-21 05:49:21 ERROR (MainThread) [homeassistant.components.plex.server] Could not connect to Plex server: KSrv02 (HTTPSConnectionPool(host='79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct', port=32400): Max retries exceeded with url: /clients (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0xffff9d9f5d30>, 'Connection to 79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct timed out. (connect timeout=30)')))
2021-01-21 05:50:59 ERROR (MainThread) [homeassistant.components.plex.server] Could not connect to Plex server: KSrv02 (HTTPSConnectionPool(host='79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct', port=32400): Max retries exceeded with url: /clients (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0xffff9df0e3d0>, 'Connection to 79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct timed out. (connect timeout=30)')))
2021-01-21 05:52:37 ERROR (MainThread) [homeassistant.components.plex.server] Could not connect to Plex server: KSrv02 (HTTPSConnectionPool(host='79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct', port=32400): Max retries exceeded with url: /clients (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0xffffa9f05130>, 'Connection to 79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct timed out. (connect timeout=30)')))
2021-01-21 05:54:12 ERROR (MainThread) [homeassistant.components.plex.server] Could not connect to Plex server: KSrv02 (HTTPSConnectionPool(host='79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct', port=32400): Max retries exceeded with url: /clients (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0xffff923b9e20>, 'Connection to 79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct timed out. (connect timeout=30)')))
2021-01-21 05:55:51 ERROR (MainThread) [homeassistant.components.plex.server] Could not connect to Plex server: KSrv02 (HTTPSConnectionPool(host='79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct', port=32400): Max retries exceeded with url: /clients (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0xffff8cd2ba00>, 'Connection to 79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct timed out. (connect timeout=30)')))
2021-01-21 05:56:34 ERROR (MainThread) [homeassistant.components.plex.server] Could not connect to Plex server: KSrv02 (HTTPSConnectionPool(host='79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct', port=32400): Max retries exceeded with url: /clients (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0xffff9d9f2160>, 'Connection to 79-222-72-172.ec95490c101a4c1ca3ed5792b7f9a924.plex.direct timed out. (connect timeout=30)')))

Best guess: This connection string doesn’t work anymore because the IP has changed?

Expected behaviour:

  • Setup works without manual adding of the port
  • Selection of internal IP before external IP (if that’s the real problem…)

Environment

System Health

version 2021.1.4
installation_type Home Assistant OS
dev false
hassio true
docker true
virtualenv false
python_version 3.8.7
os_name Linux
os_version 5.7.19
arch aarch64
timezone Europe/Berlin
Home Assistant Community Store
GitHub API ok
Github API Calls Remaining 4942
Installed Version 1.9.0
Stage running
Available Repositories 709
Installed Repositories 9
Home Assistant Cloud
logged_in true
subscription_expiration 12. Februar 2021, 01:00
relayer_connected true
remote_enabled false
remote_connected false
alexa_enabled true
google_enabled false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Hass.io
host_os HassOS 4.20
update_channel stable
supervisor_version 2021.01.5
docker_version 19.03.12
disk_total 113.9 GB
disk_used 2.8 GB
healthy true
supported true
board odroid-n2
supervisor_api ok
version_api ok
installed_addons File editor (5.2.0), Check Home Assistant configuration (3.6.0), FTP (3.5.0), Terminal & SSH (8.10.0), Duck DNS (1.12.4), Log Viewer (0.9.1), CEC Scanner (2.4)
Lovelace
dashboards 2
mode storage
views 6
resources 2

Problem-relevant configuration.yaml

None - config via GUI.

Traceback/Error logs

Integrated above.

Additional information

I have changed to manual configuration using the local IP and will add further information in comments in the next couple of days how it behaves after IP change.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 35 (19 by maintainers)

Most upvoted comments

Thanks for the info - and once again: Great job on the Plex integration, just saw the enhancements. I submitted a small PR for update of the documentation.

As this is all cleared up I will close this now, please feel free to reopen if you have something more to add…

Not every user will be able to disable rebinding protection, either because it’s somewhat complex or they have an ISP-provided router that’s locked down. I’ll look into adding the feature in point (2) when I have more spare time.