From e58d98bc1042692fd5a2fab61a893a43c5eeb08c Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Tue, 4 Oct 2016 01:14:14 -0500 Subject: [PATCH] Catch and raise bad status 400 When the request is malformed. Added logging to hopefully get to the bottom of a bug pulling albums from server. --- resources/lib/downloadutils.py | 5 +++++ resources/lib/read_embyserver.py | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 066faa46..9b182b20 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -248,6 +248,7 @@ class DownloadUtils(object): ##### THE RESPONSE ##### log.debug(kwargs) response = self._requests(action_type, session, **kwargs) + #response = requests.get('http://httpbin.org/status/400') if response.status_code == 204: # No body in the response @@ -287,6 +288,10 @@ class DownloadUtils(object): except requests.exceptions.HTTPError as error: + if response.status_code == 400: + log.error("Malformed request: %s", error) + raise Warning('400') + if response.status_code == 401: # Unauthorized status = window('emby_serverStatus') diff --git a/resources/lib/read_embyserver.py b/resources/lib/read_embyserver.py index 5ff44c49..78eec671 100644 --- a/resources/lib/read_embyserver.py +++ b/resources/lib/read_embyserver.py @@ -186,7 +186,8 @@ class Read_EmbyServer(): url = "{server}/emby/LiveTv/Recordings/?userid={UserId}&format=json" return self.doUtils(url, parameters=params) - def getSection(self, parentid, itemtype=None, sortby="SortName", basic=False, dialog=None): + def getSection(self, parentid, itemtype=None, sortby="SortName", basic=False, params=None, + dialog=None): items = { @@ -238,7 +239,7 @@ class Read_EmbyServer(): if basic: params['Fields'] = "Etag" else: - params['Fields'] = ( + params['Fields'] = params or ( "Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines," "CommunityRating,OfficialRating,CumulativeRunTimeTicks," @@ -247,9 +248,13 @@ class Read_EmbyServer(): "Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers," "MediaSources,VoteCount" ) - result = self.doUtils(url, parameters=params) try: + result = self.doUtils(url, parameters=params) items['Items'].extend(result['Items']) + except Warning as error: + if error == "400": + log.info("Something went wrong, aborting request.") + break except TypeError: # Something happened to the connection if not throttled: