From 2aa1b43811293c783ef1562186eb17d04af63233 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 28 Aug 2026 22:31:56 +0200 Subject: [PATCH] Restore Plex recovery from a changed plex.direct certificate (#180446) --- homeassistant/components/plex/server.py | 5 +++-- tests/components/plex/test_init.py | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/plex/server.py b/homeassistant/components/plex/server.py index d0b967fa4249..36125fc5bece 100644 --- a/homeassistant/components/plex/server.py +++ b/homeassistant/components/plex/server.py @@ -191,8 +191,9 @@ class PlexServer: error = error.__context__ if isinstance(error, ssl.SSLCertVerificationError): domain = urlparse(self._url).netloc.split(":")[0] - if domain.endswith("plex.direct") and error.args[0].startswith( - f"hostname '{domain}' doesn't match" + # OpenSSL's own wording for X509_V_ERR_HOSTNAME_MISMATCH + if domain.endswith("plex.direct") and "Hostname mismatch" in str( + error ): _LOGGER.warning( "Plex SSL certificate's hostname changed, updating" diff --git a/tests/components/plex/test_init.py b/tests/components/plex/test_init.py index 036b2d87f3fa..e26663cbe30b 100644 --- a/tests/components/plex/test_init.py +++ b/tests/components/plex/test_init.py @@ -210,8 +210,11 @@ async def test_setup_when_certificate_changed( """Mock the exception showing a mismatched hostname.""" def __init__(self) -> None: # pylint: disable=super-init-not-called + # Shaped the way it is really raised: OSError args of (errno, message) self.__context__ = ssl.SSLCertVerificationError( - f"hostname '{old_domain}' doesn't match" + 1, + "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:" + f" Hostname mismatch, certificate is not valid for '{old_domain}'.", ) old_domain = "1-2-3-4.1111111111ffffff1111111111ffffff.plex.direct"