diff --git a/media/radarr.py b/media/radarr.py index bc0c3af..981af7e 100644 --- a/media/radarr.py +++ b/media/radarr.py @@ -1,9 +1,11 @@ +import os.path + import backoff import requests -import os.path -from misc.log import logger from misc import helpers +from misc import str as misc_str +from misc.log import logger log = logger.get_logger(__name__) @@ -27,7 +29,7 @@ class Radarr: try: # request system status to validate api_key req = requests.get( - os.path.join(self.server_url, 'api/system/status'), + os.path.join(misc_str.ensure_endswith(self.server_url, "/"), 'api/system/status'), headers=self.headers, timeout=60 ) @@ -45,7 +47,7 @@ class Radarr: try: # make request req = requests.get( - os.path.join(self.server_url, 'api/movie'), + os.path.join(misc_str.ensure_endswith(self.server_url, "/"), 'api/movie'), headers=self.headers, timeout=60 ) @@ -67,7 +69,7 @@ class Radarr: try: # make request req = requests.get( - os.path.join(self.server_url, 'api/profile'), + os.path.join(misc_str.ensure_endswith(self.server_url, "/"), 'api/profile'), headers=self.headers, timeout=60 ) @@ -111,7 +113,7 @@ class Radarr: # make request req = requests.post( - os.path.join(self.server_url, 'api/movie'), + os.path.join(misc_str.ensure_endswith(self.server_url, "/"), 'api/movie'), headers=self.headers, json=payload, timeout=60 diff --git a/media/sonarr.py b/media/sonarr.py index 9315c62..6caa082 100644 --- a/media/sonarr.py +++ b/media/sonarr.py @@ -1,8 +1,10 @@ +import os.path + import backoff import requests -import os.path from misc import helpers +from misc import str as misc_str from misc.log import logger log = logger.get_logger(__name__) @@ -25,7 +27,8 @@ class Sonarr: def validate_api_key(self): try: # request system status to validate api_key - req = requests.get(os.path.join(self.server_url, 'api/system/status'), headers=self.headers, timeout=60) + req = requests.get(os.path.join(misc_str.ensure_endswith(self.server_url, "/"), 'api/system/status'), + headers=self.headers, timeout=60) log.debug("Request Response: %d", req.status_code) if req.status_code == 200 and 'version' in req.json(): @@ -40,7 +43,7 @@ class Sonarr: try: # make request req = requests.get( - os.path.join(self.server_url, 'api/series'), + os.path.join(misc_str.ensure_endswith(self.server_url, "/"), 'api/series'), headers=self.headers, timeout=60 ) @@ -62,7 +65,7 @@ class Sonarr: try: # make request req = requests.get( - os.path.join(self.server_url, 'api/profile'), + os.path.join(misc_str.ensure_endswith(self.server_url, "/"), 'api/profile'), headers=self.headers, timeout=60 ) @@ -88,7 +91,7 @@ class Sonarr: try: # make request req = requests.get( - os.path.join(self.server_url, 'api/tag'), + os.path.join(misc_str.ensure_endswith(self.server_url, "/"), 'api/tag'), headers=self.headers, timeout=60 ) @@ -115,7 +118,7 @@ class Sonarr: try: # make request req = requests.get( - os.path.join(self.server_url, 'api/tag'), + os.path.join(misc_str.ensure_endswith(self.server_url, "/"), 'api/tag'), headers=self.headers, timeout=60 ) @@ -159,7 +162,7 @@ class Sonarr: # make request req = requests.post( - os.path.join(self.server_url, 'api/series'), + os.path.join(misc_str.ensure_endswith(self.server_url, "/"), 'api/series'), headers=self.headers, json=payload, timeout=60 diff --git a/misc/str.py b/misc/str.py index 91c9cab..e278409 100644 --- a/misc/str.py +++ b/misc/str.py @@ -26,3 +26,10 @@ def is_ascii(string): log.exception(u"Exception checking if %r was ascii: ", string) return False return True + + +def ensure_endswith(data, endswith_key): + if not data.strip().endswith(endswith_key): + return "%s%s" % (data.strip(), endswith_key) + else: + return data