From eac46b0d138d323d40ecf84813a8aa56db558a4c Mon Sep 17 00:00:00 2001 From: Nick Heyer Date: Sun, 1 Dec 2024 14:51:41 -0800 Subject: [PATCH] Fixed additional slashes --- DiscoFlixBot/lib/api/requests.py | 11 ++++++----- DiscoFlixBot/lib/api/sonarr.py | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/DiscoFlixBot/lib/api/requests.py b/DiscoFlixBot/lib/api/requests.py index b5a9f34..ee1d6a6 100644 --- a/DiscoFlixBot/lib/api/requests.py +++ b/DiscoFlixBot/lib/api/requests.py @@ -12,7 +12,7 @@ def __init__(self, host_url=None, api_key=None): host_url (str): Host url to sonarr/radarr. api_key: API key from sonarr/radarr. """ - self.host_url = host_url + self.host_url = host_url.rstrip('/') self.api_key = api_key self.session = requests.Session() self.auth = None @@ -41,7 +41,7 @@ def request_get(self, path: str, **data) -> dict: """ headers = {"X-Api-Key": self.api_key} - request_url = f"{self.host_url}{path}" + request_url = f"{self.host_url}/{path.lstrip('/')}" try: response = self.session.get( @@ -62,7 +62,7 @@ def request_post(self, path: str, data: dict) -> dict: dict: Response JSON data. """ headers = {"X-Api-Key": self.api_key} - request_url = f"{self.host_url}{path}" + request_url = f"{self.host_url}/{path.lstrip('/')}" try: response = self.session.post( request_url, headers=headers, json=data, auth=self.auth @@ -82,7 +82,7 @@ def request_put(self, path: str, data: dict) -> dict: dict: Response JSON data. """ headers = {"X-Api-Key": self.api_key} - request_url = f"{self.host_url}{path}" + request_url = f"{self.host_url}/{path.lstrip('/')}" try: response = self.session.put( request_url, headers=headers, json=data, auth=self.auth @@ -102,7 +102,7 @@ def request_delete(self, path: str, data: dict) -> dict: dict: Response JSON data. """ headers = {"X-Api-Key": self.api_key} - request_url = f"{self.host_url}{path}" + request_url = f"{self.host_url}/{path.lstrip('/')}" try: response = self.session.delete( request_url, headers=headers, json=data, auth=self.auth @@ -115,3 +115,4 @@ def request_delete(self, path: str, data: dict) -> dict: except ValueError: # Catch JSON decode error in case the response has no body return {} + diff --git a/DiscoFlixBot/lib/api/sonarr.py b/DiscoFlixBot/lib/api/sonarr.py index 50fff3c..ee3c91e 100644 --- a/DiscoFlixBot/lib/api/sonarr.py +++ b/DiscoFlixBot/lib/api/sonarr.py @@ -527,4 +527,5 @@ def get_or_create_tag(self, tag_name="DF"): return existing else: new = self.create_tag(label=tag_name) - return new.get('id', -1) \ No newline at end of file + return new.get('id', -1) + \ No newline at end of file