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 backoff
import requests import requests
import os.path
from misc.log import logger
from misc import helpers from misc import helpers
from misc import str as misc_str
from misc.log import logger
log = logger.get_logger(__name__) log = logger.get_logger(__name__)
@ -27,7 +29,7 @@ class Radarr:
try: try:
# request system status to validate api_key # request system status to validate api_key
req = requests.get( 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, headers=self.headers,
timeout=60 timeout=60
) )
@ -45,7 +47,7 @@ class Radarr:
try: try:
# make request # make request
req = requests.get( 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, headers=self.headers,
timeout=60 timeout=60
) )
@ -67,7 +69,7 @@ class Radarr:
try: try:
# make request # make request
req = requests.get( 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, headers=self.headers,
timeout=60 timeout=60
) )
@ -111,7 +113,7 @@ class Radarr:
# make request # make request
req = requests.post( 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, headers=self.headers,
json=payload, json=payload,
timeout=60 timeout=60

@ -1,8 +1,10 @@
import os.path
import backoff import backoff
import requests import requests
import os.path
from misc import helpers from misc import helpers
from misc import str as misc_str
from misc.log import logger from misc.log import logger
log = logger.get_logger(__name__) log = logger.get_logger(__name__)
@ -25,7 +27,8 @@ class Sonarr:
def validate_api_key(self): def validate_api_key(self):
try: try:
# request system status to validate api_key # 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) log.debug("Request Response: %d", req.status_code)
if req.status_code == 200 and 'version' in req.json(): if req.status_code == 200 and 'version' in req.json():
@ -40,7 +43,7 @@ class Sonarr:
try: try:
# make request # make request
req = requests.get( 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, headers=self.headers,
timeout=60 timeout=60
) )
@ -62,7 +65,7 @@ class Sonarr:
try: try:
# make request # make request
req = requests.get( 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, headers=self.headers,
timeout=60 timeout=60
) )
@ -88,7 +91,7 @@ class Sonarr:
try: try:
# make request # make request
req = requests.get( 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, headers=self.headers,
timeout=60 timeout=60
) )
@ -115,7 +118,7 @@ class Sonarr:
try: try:
# make request # make request
req = requests.get( 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, headers=self.headers,
timeout=60 timeout=60
) )
@ -159,7 +162,7 @@ class Sonarr:
# make request # make request
req = requests.post( 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, headers=self.headers,
json=payload, json=payload,
timeout=60 timeout=60

@ -26,3 +26,10 @@ def is_ascii(string):
log.exception(u"Exception checking if %r was ascii: ", string) log.exception(u"Exception checking if %r was ascii: ", string)
return False return False
return True 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