Better exception handling and logging when calling Sonarr and Radarr

pull/115/merge
morpheus65535 6 years ago
parent 8825a83c95
commit ad4203fb8e

@ -130,7 +130,7 @@ def image_proxy(url):
apikey = get_sonarr_settings()[2]
url_image = url_sonarr_short + '/' + url + '?apikey=' + apikey
try:
img_pil = Image.open(BytesIO(requests.get(url_sonarr_short + '/api' + url_image.split(url_sonarr)[1]).content))
img_pil = Image.open(BytesIO(requests.get(url_sonarr_short + '/api' + url_image.split(url_sonarr)[1], timeout=15).content))
except:
return None
else:
@ -148,10 +148,10 @@ def image_proxy_movies(url):
apikey = get_radarr_settings()[2]
try:
url_image = (url_radarr_short + '/' + url + '?apikey=' + apikey).replace('/fanart.jpg', '/banner.jpg')
img_pil = Image.open(BytesIO(requests.get(url_radarr_short + '/api' + url_image.split(url_radarr)[1]).content))
img_pil = Image.open(BytesIO(requests.get(url_radarr_short + '/api' + url_image.split(url_radarr)[1], timeout=15).content))
except:
url_image = url_radarr_short + '/' + url + '?apikey=' + apikey
img_pil = Image.open(BytesIO(requests.get(url_radarr_short + '/api' + url_image.split(url_radarr)[1]).content))
img_pil = Image.open(BytesIO(requests.get(url_radarr_short + '/api' + url_image.split(url_radarr)[1], timeout=15).content))
img_buffer = BytesIO()
img_pil.tobytes()

@ -36,7 +36,18 @@ def sync_episodes():
for seriesId in seriesIdList:
# Get episodes data for a series from Sonarr
url_sonarr_api_episode = url_sonarr + "/api/episode?seriesId=" + str(seriesId[0]) + "&apikey=" + apikey_sonarr
r = requests.get(url_sonarr_api_episode)
try:
r = requests.get(url_sonarr_api_episode, timeout=15)
r.raise_for_status()
except requests.exceptions.HTTPError as errh:
logging.exception("Error trying to get episodes from Sonarr. Http error.")
except requests.exceptions.ConnectionError as errc:
logging.exception("Error trying to get episodes from Sonarr. Connection Error.")
except requests.exceptions.Timeout as errt:
logging.exception("Error trying to get episodes from Sonarr. Timeout Error.")
except requests.exceptions.RequestException as err:
logging.exception("Error trying to get episodes from Sonarr.")
else:
for episode in r.json():
if 'hasFile' in episode:
if episode['hasFile'] is True:

@ -1,6 +1,7 @@
import os
import sqlite3
import requests
import logging
from get_general_settings import *
from list_subtitles import *
@ -25,8 +26,18 @@ def update_movies():
# Get movies data from radarr
url_radarr_api_movies = url_radarr + "/api/movie?apikey=" + apikey_radarr
r = requests.get(url_radarr_api_movies)
try:
r = requests.get(url_radarr_api_movies, timeout=15)
r.raise_for_status()
except requests.exceptions.HTTPError as errh:
logging.exception("Error trying to get movies from Radarr. Http error.")
except requests.exceptions.ConnectionError as errc:
logging.exception("Error trying to get movies from Radarr. Connection Error.")
except requests.exceptions.Timeout as errt:
logging.exception("Error trying to get movies from Radarr. Timeout Error.")
except requests.exceptions.RequestException as err:
logging.exception("Error trying to get movies from Radarr.")
else:
# Get current movies in DB
current_movies_db = c.execute('SELECT tmdbId FROM table_movies').fetchall()
current_movies_db_list = [x[0] for x in current_movies_db]
@ -101,11 +112,19 @@ def get_profile_list():
apikey_radarr = get_radarr_settings()[2]
# Get profiles data from radarr
url_radarr_api_movies = url_radarr + "/api/profile?apikey=" + apikey_radarr
profiles_json = requests.get(url_radarr_api_movies)
global profiles_list
profiles_list = []
url_radarr_api_movies = url_radarr + "/api/profile?apikey=" + apikey_radarr
try:
profiles_json = requests.get(url_radarr_api_movies, timeout=15)
except requests.exceptions.ConnectionError as errc:
logging.exception("Error trying to get profiles from Sonarr. Connection Error.")
except requests.exceptions.Timeout as errt:
logging.exception("Error trying to get profiles from Sonarr. Timeout Error.")
except requests.exceptions.RequestException as err:
logging.exception("Error trying to get profiles from Sonarr.")
else:
# Parsing data returned from radarr
for profile in profiles_json.json():
profiles_list.append([profile['id'], profile['language'].capitalize()])

@ -1,6 +1,7 @@
import os
import sqlite3
import requests
import logging
from get_general_settings import *
from list_subtitles import *
@ -25,8 +26,18 @@ def update_series():
# Get shows data from Sonarr
url_sonarr_api_series = url_sonarr + "/api/series?apikey=" + apikey_sonarr
r = requests.get(url_sonarr_api_series)
try:
r = requests.get(url_sonarr_api_series, timeout=15)
r.raise_for_status()
except requests.exceptions.HTTPError as errh:
logging.exception("Error trying to get series from Sonarr. Http error.")
except requests.exceptions.ConnectionError as errc:
logging.exception("Error trying to get series from Sonarr. Connection Error.")
except requests.exceptions.Timeout as errt:
logging.exception("Error trying to get series from Sonarr. Timeout Error.")
except requests.exceptions.RequestException as err:
logging.exception("Error trying to get series from Sonarr.")
else:
# Get current shows in DB
current_shows_db = c.execute('SELECT tvdbId FROM table_shows').fetchall()
current_shows_db_list = [x[0] for x in current_shows_db]
@ -80,13 +91,38 @@ def get_profile_list():
apikey_sonarr = get_sonarr_settings()[2]
# Get profiles data from Sonarr
error = False
url_sonarr_api_series = url_sonarr + "/api/profile?apikey=" + apikey_sonarr
profiles_json = requests.get(url_sonarr_api_series)
try:
profiles_json = requests.get(url_sonarr_api_series, timeout=15)
except requests.exceptions.ConnectionError as errc:
error = True
logging.exception("Error trying to get profiles from Sonarr. Connection Error.")
except requests.exceptions.Timeout as errt:
error = True
logging.exception("Error trying to get profiles from Sonarr. Timeout Error.")
except requests.exceptions.RequestException as err:
error = True
logging.exception("Error trying to get profiles from Sonarr.")
url_sonarr_api_series_v3 = url_sonarr + "/api/v3/languageprofile?apikey=" + apikey_sonarr
profiles_json_v3 = requests.get(url_sonarr_api_series_v3)
try:
profiles_json_v3 = requests.get(url_sonarr_api_series_v3, timeout=15)
except requests.exceptions.ConnectionError as errc:
error = True
logging.exception("Error trying to get profiles from Sonarr. Connection Error.")
except requests.exceptions.Timeout as errt:
error = True
logging.exception("Error trying to get profiles from Sonarr. Timeout Error.")
except requests.exceptions.RequestException as err:
error = True
logging.exception("Error trying to get profiles from Sonarr.")
global profiles_list
profiles_list = []
if error is False:
# Parsing data returned from Sonarr
global sonarr_version
if type(profiles_json_v3.json()) != list:

Loading…
Cancel
Save