From a1bda39e9d129cb077836c5e7793833109ad7b64 Mon Sep 17 00:00:00 2001 From: croneter Date: Fri, 21 Feb 2020 08:22:09 +0100 Subject: [PATCH] Correctly detect whether we can use SSL to connect to the PMS --- resources/lib/plex_functions.py | 39 ++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/resources/lib/plex_functions.py b/resources/lib/plex_functions.py index 52e403d7..c9e29491 100644 --- a/resources/lib/plex_functions.py +++ b/resources/lib/plex_functions.py @@ -846,28 +846,31 @@ def _pms_https_enabled(url): Prefers HTTPS over HTTP """ - res = DU().downloadUrl('https://%s/identity' % url, - authenticate=False, - verifySSL=True if v.KODIVERSION >= 18 else False) + # Try HTTPS first try: - res.attrib - except AttributeError: - # Might have SSL deactivated. Try with http - res = DU().downloadUrl('http://%s/identity' % url, - authenticate=False, - verifySSL=True if v.KODIVERSION >= 18 else False) - try: - res.attrib - except AttributeError: - LOG.error("Could not contact PMS %s", url) - return None - else: - # Received a valid XML. Server wants to talk HTTP - return False + DU().downloadUrl('https://%s/identity' % url, + authenticate=False, + reraise=True) + except exceptions.SSLError: + LOG.debug('SSLError trying to connect to https://%s/identity', url) + except Exception as e: + LOG.info('Couldnt check https connection to https://%s/identity: %s', + url, e) else: - # Received a valid XML. Server wants to talk HTTPS return True + # Try HTTP next + try: + DU().downloadUrl('http://%s/identity' % url, + authenticate=False, + reraise=True) + except Exception as e: + LOG.info('Couldnt check http connection to http://%s/identity: %s', + url, e) + return + else: + return False + def GetMachineIdentifier(url): """