ensure server url ends with /

pull/54/head
l3uddz 7 years ago
parent a7a0751b0b
commit 482c11dbec

@ -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

@ -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

@ -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

Loading…
Cancel
Save