From 10e79bbbad2b81b29c99d44a34d5e3b90a6da573 Mon Sep 17 00:00:00 2001 From: Abby Gourlay Date: Thu, 19 Mar 2020 22:15:02 +0000 Subject: [PATCH] Fixed http fallback --- jellyfin_kodi/jellyfin/api.py | 17 ++++++++++++++++- jellyfin_kodi/jellyfin/connection_manager.py | 14 +++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/jellyfin_kodi/jellyfin/api.py b/jellyfin_kodi/jellyfin/api.py index db074e28..f7818015 100644 --- a/jellyfin_kodi/jellyfin/api.py +++ b/jellyfin_kodi/jellyfin/api.py @@ -386,7 +386,22 @@ class API(object): LOG.debug(request_settings['timeout']) LOG.debug(request_settings['headers']) - return request_method(url, **request_settings) + try: + return request_method(url, **request_settings) + except requests.exceptions.SSLError as e: + LOG.error("Failed to connect to server. SSL Issue: %s" % e) + response = requests.Response() + response.code = "SSL Error: %s".format(e) + response.error_type = "SSLError" + response.status_code = 500 + return response + except Exception as e: + LOG.error("Failed to connect to server. Unhandled Issue: %s" % e) + response = requests.Response() + response.code = e + response.error_type = "UnhandledError" + response.status_code = 500 + return response def login(self, server_url, username, password=""): diff --git a/jellyfin_kodi/jellyfin/connection_manager.py b/jellyfin_kodi/jellyfin/connection_manager.py index fc74adbc..d99bc994 100644 --- a/jellyfin_kodi/jellyfin/connection_manager.py +++ b/jellyfin_kodi/jellyfin/connection_manager.py @@ -134,6 +134,10 @@ class ConnectionManager(object): try: public_info = self.API.get_public_info(address) + if not public_info: + LOG.error("connectToAddress %s failed", address) + return { 'State': CONNECTION_STATE['Unavailable'] } + LOG.info("connectToAddress %s succeeded", address) server = { 'address': address, @@ -286,18 +290,18 @@ class ConnectionManager(object): # Attempt to correct bad input url = urllib3.util.parse_url(address.strip()) - # Default to using https + # Default to using https url = url._replace(scheme='https') - + # Test if server is reachable over https if self.API.get_public_info(url): - if url.scheme == 'https' and url.port == 443: + if url.port == 443: url = url._replace(port=None) else: # Server didn't give an expected response over https # Try http instead - url._replace(scheme='http') - if url.scheme == 'http' and url.port == 80: + url = url._replace(scheme='http') + if url.port == 80: url = url._replace(port=None) return url.url