From 057921b05e768d759cbdaf9de0ed15905378a67c Mon Sep 17 00:00:00 2001 From: croneter Date: Fri, 24 Sep 2021 16:59:41 +0200 Subject: [PATCH 1/2] Fix download not always returning entire requests.response object --- resources/lib/downloadutils.py | 9 +++++---- resources/lib/plex_api/media.py | 15 +++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 678876c4..33ee72df 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -224,7 +224,11 @@ class DownloadUtils(): if r.status_code != 401: self.count_unauthorized = 0 - if r.status_code == 204: + if return_response is True: + # return the entire response object + return r + + elif r.status_code == 204: # No body in the response # But read (empty) content to release connection back to pool # (see requests: keep-alive documentation) @@ -258,9 +262,6 @@ class DownloadUtils(): elif r.status_code in (200, 201): # 200: OK # 201: Created - if return_response is True: - # return the entire response object - return r try: # xml response r = utils.defused_etree.fromstring(r.content) diff --git a/resources/lib/plex_api/media.py b/resources/lib/plex_api/media.py index 52e10262..4246f03a 100644 --- a/resources/lib/plex_api/media.py +++ b/resources/lib/plex_api/media.py @@ -320,16 +320,15 @@ class Media(object): filename, extension) response = DU().downloadUrl(url, return_response=True) - try: - response.status_code - except AttributeError: + if not response.ok: LOG.error('Could not temporarily download subtitle %s', url) + LOG.error('HTTP status: %s, message: %s', + response.status_code, response.text) return - else: - LOG.debug('Writing temp subtitle to %s', path) - with open(path_ops.encode_path(path), 'wb') as f: - f.write(response.content) - return path + LOG.debug('Writing temp subtitle to %s', path) + with open(path_ops.encode_path(path), 'wb') as f: + f.write(response.content) + return path def validate_playurl(self, path, typus, force_check=False, folder=False, omit_check=False): From e96df700c12e8340ada45f48b7d10c352a64ac70 Mon Sep 17 00:00:00 2001 From: croneter Date: Fri, 24 Sep 2021 16:24:57 +0200 Subject: [PATCH 2/2] Fix logging if fanart.tv lookup fails --- resources/lib/plex_api/artwork.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/resources/lib/plex_api/artwork.py b/resources/lib/plex_api/artwork.py index 632d4355..08841a35 100644 --- a/resources/lib/plex_api/artwork.py +++ b/resources/lib/plex_api/artwork.py @@ -222,12 +222,14 @@ class Artwork(object): else: # Not supported artwork return artworks - data = DU().downloadUrl(url, authenticate=False, timeout=15) - try: - data.get('test') - except AttributeError: - LOG.error('Could not download data from FanartTV') + data = DU().downloadUrl(url, + authenticate=False, + timeout=15, + return_response=True) + if not data.ok: + LOG.debug('Could not download data from FanartTV') return artworks + data = data.json() fanart_tv_types = list(v.FANART_TV_TO_KODI_TYPE)