From cd17eb53141547171288664bc34eccfed5c86bd7 Mon Sep 17 00:00:00 2001 From: l3uddz Date: Wed, 18 Apr 2018 13:14:03 +0100 Subject: [PATCH] check for json in response content-type and log a debug message for response text. --- media/radarr.py | 6 ++++-- media/sonarr.py | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/media/radarr.py b/media/radarr.py index 57e761c..3f517cc 100644 --- a/media/radarr.py +++ b/media/radarr.py @@ -93,9 +93,11 @@ class Radarr: req = requests.post(urljoin(self.server_url, 'api/movie'), json=payload, headers=self.headers, timeout=30) log.debug("Request URL: %s", req.url) log.debug("Request Payload: %s", payload) - log.debug("Request Response: %d", req.status_code) + log.debug("Request Response Code: %d", req.status_code) + log.debug("Request Response Text:\n%s", req.text) - if (req.status_code == 201 or req.status_code == 200) and req.json()['tmdbId'] == movie_tmdbid: + if (req.status_code == 201 or req.status_code == 200) and 'json' in req.headers['Content-Type'].lower() \ + and req.json()['tmdbId'] == movie_tmdbid: log.debug("Successfully added %s (%d)", movie_title, movie_tmdbid) return True elif 'json' in req.headers['Content-Type'].lower() and 'message' in req.text: diff --git a/media/sonarr.py b/media/sonarr.py index 11e86ad..1d10f16 100644 --- a/media/sonarr.py +++ b/media/sonarr.py @@ -139,9 +139,11 @@ class Sonarr: req = requests.post(urljoin(self.server_url, 'api/series'), json=payload, headers=self.headers, timeout=30) log.debug("Request URL: %s", req.url) log.debug("Request Payload: %s", payload) - log.debug("Request Response: %d", req.status_code) - - if (req.status_code == 201 or req.status_code == 200) and req.json()['tvdbId'] == series_tvdbid: + log.debug("Request Response Code: %d", req.status_code) + log.debug("Request Response Text:\n%s", req.text) + + if (req.status_code == 201 or req.status_code == 200) and 'json' in req.headers['Content-Type'].lower() \ + and req.json()['tvdbId'] == series_tvdbid: log.debug("Successfully added %s (%d)", series_title, series_tvdbid) return True elif 'json' in req.headers['Content-Type'].lower() and 'errorMessage' in req.text: