Added configurable request timeout to Sonarr and Radarr

pull/2052/head v1.1.5-beta.7
Cory Metcalfe 2 years ago committed by GitHub
parent cf4571ba86
commit f5d7b4d321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -101,6 +101,7 @@ defaults = {
'port': '8989', 'port': '8989',
'base_url': '/', 'base_url': '/',
'ssl': 'False', 'ssl': 'False',
'http_timeout': '60',
'apikey': '', 'apikey': '',
'full_update': 'Daily', 'full_update': 'Daily',
'full_update_day': '6', 'full_update_day': '6',
@ -119,6 +120,7 @@ defaults = {
'port': '7878', 'port': '7878',
'base_url': '/', 'base_url': '/',
'ssl': 'False', 'ssl': 'False',
'http_timeout': '60',
'apikey': '', 'apikey': '',
'full_update': 'Daily', 'full_update': 'Daily',
'full_update_day': '6', 'full_update_day': '6',

@ -21,7 +21,7 @@ def browse_radarr_filesystem(path='#'):
"&allowFoldersWithoutTrailingSlashes=true&includeFiles=false&apikey=" + \ "&allowFoldersWithoutTrailingSlashes=true&includeFiles=false&apikey=" + \
settings.radarr.apikey settings.radarr.apikey
try: try:
r = requests.get(url_radarr_api_filesystem, timeout=60, verify=False, headers=headers) r = requests.get(url_radarr_api_filesystem, timeout=int(settings.radarr.http_timeout), verify=False, headers=headers)
r.raise_for_status() r.raise_for_status()
except requests.exceptions.HTTPError: except requests.exceptions.HTTPError:
logging.exception("BAZARR Error trying to get series from Radarr. Http error.") logging.exception("BAZARR Error trying to get series from Radarr. Http error.")

@ -29,7 +29,7 @@ class GetRadarrInfo:
if settings.general.getboolean('use_radarr'): if settings.general.getboolean('use_radarr'):
try: try:
rv = url_radarr() + "/api/system/status?apikey=" + settings.radarr.apikey rv = url_radarr() + "/api/system/status?apikey=" + settings.radarr.apikey
radarr_json = requests.get(rv, timeout=60, verify=False, headers=headers).json() radarr_json = requests.get(rv, timeout=int(settings.radarr.http_timeout), verify=False, headers=headers).json()
if 'version' in radarr_json: if 'version' in radarr_json:
radarr_version = radarr_json['version'] radarr_version = radarr_json['version']
else: else:
@ -37,7 +37,7 @@ class GetRadarrInfo:
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
try: try:
rv = url_radarr() + "/api/v3/system/status?apikey=" + settings.radarr.apikey rv = url_radarr() + "/api/v3/system/status?apikey=" + settings.radarr.apikey
radarr_version = requests.get(rv, timeout=60, verify=False, headers=headers).json()['version'] radarr_version = requests.get(rv, timeout=int(settings.radarr.http_timeout), verify=False, headers=headers).json()['version']
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
logging.debug('BAZARR cannot get Radarr version') logging.debug('BAZARR cannot get Radarr version')
radarr_version = 'unknown' radarr_version = 'unknown'

@ -18,6 +18,6 @@ def notify_radarr(radarr_id):
'name': 'RescanMovie', 'name': 'RescanMovie',
'movieId': int(radarr_id) 'movieId': int(radarr_id)
} }
requests.post(url, json=data, timeout=60, verify=False, headers=headers) requests.post(url, json=data, timeout=int(settings.radarr.http_timeout), verify=False, headers=headers)
except Exception: except Exception:
logging.exception('BAZARR cannot notify Radarr') logging.exception('BAZARR cannot notify Radarr')

@ -22,7 +22,7 @@ def get_radarr_rootfolder():
url_radarr_api_rootfolder = url_radarr() + "/api/v3/rootfolder?apikey=" + apikey_radarr url_radarr_api_rootfolder = url_radarr() + "/api/v3/rootfolder?apikey=" + apikey_radarr
try: try:
rootfolder = requests.get(url_radarr_api_rootfolder, timeout=60, verify=False, headers=headers) rootfolder = requests.get(url_radarr_api_rootfolder, timeout=int(settings.radarr.http_timeout), verify=False, headers=headers)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
logging.exception("BAZARR Error trying to get rootfolder from Radarr. Connection Error.") logging.exception("BAZARR Error trying to get rootfolder from Radarr. Connection Error.")
return [] return []

@ -18,7 +18,7 @@ def get_profile_list():
url_radarr_api_movies = url_radarr() + "/api/v3/qualityprofile?apikey=" + apikey_radarr url_radarr_api_movies = url_radarr() + "/api/v3/qualityprofile?apikey=" + apikey_radarr
try: try:
profiles_json = requests.get(url_radarr_api_movies, timeout=60, verify=False, headers=headers) profiles_json = requests.get(url_radarr_api_movies, timeout=int(settings.radarr.http_timeout), verify=False, headers=headers)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
logging.exception("BAZARR Error trying to get profiles from Radarr. Connection Error.") logging.exception("BAZARR Error trying to get profiles from Radarr. Connection Error.")
except requests.exceptions.Timeout: except requests.exceptions.Timeout:
@ -50,7 +50,7 @@ def get_tags():
url_radarr_api_series = url_radarr() + "/api/v3/tag?apikey=" + apikey_radarr url_radarr_api_series = url_radarr() + "/api/v3/tag?apikey=" + apikey_radarr
try: try:
tagsDict = requests.get(url_radarr_api_series, timeout=60, verify=False, headers=headers) tagsDict = requests.get(url_radarr_api_series, timeout=int(settings.radarr.http_timeout), verify=False, headers=headers)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
logging.exception("BAZARR Error trying to get tags from Radarr. Connection Error.") logging.exception("BAZARR Error trying to get tags from Radarr. Connection Error.")
return [] return []
@ -79,7 +79,7 @@ def get_movies_from_radarr_api(url, apikey_radarr, radarr_id=None):
apikey_radarr apikey_radarr
try: try:
r = requests.get(url_radarr_api_movies, timeout=60, verify=False, headers=headers) r = requests.get(url_radarr_api_movies, timeout=int(settings.radarr.http_timeout), verify=False, headers=headers)
if r.status_code == 404: if r.status_code == 404:
return return
r.raise_for_status() r.raise_for_status()

@ -20,7 +20,7 @@ def browse_sonarr_filesystem(path='#'):
"&allowFoldersWithoutTrailingSlashes=true&includeFiles=false&apikey=" + \ "&allowFoldersWithoutTrailingSlashes=true&includeFiles=false&apikey=" + \
settings.sonarr.apikey settings.sonarr.apikey
try: try:
r = requests.get(url_sonarr_api_filesystem, timeout=60, verify=False, headers=headers) r = requests.get(url_sonarr_api_filesystem, timeout=int(settings.sonarr.http_timeout), verify=False, headers=headers)
r.raise_for_status() r.raise_for_status()
except requests.exceptions.HTTPError: except requests.exceptions.HTTPError:
logging.exception("BAZARR Error trying to get series from Sonarr. Http error.") logging.exception("BAZARR Error trying to get series from Sonarr. Http error.")

@ -29,7 +29,7 @@ class GetSonarrInfo:
if settings.general.getboolean('use_sonarr'): if settings.general.getboolean('use_sonarr'):
try: try:
sv = url_sonarr() + "/api/system/status?apikey=" + settings.sonarr.apikey sv = url_sonarr() + "/api/system/status?apikey=" + settings.sonarr.apikey
sonarr_json = requests.get(sv, timeout=60, verify=False, headers=headers).json() sonarr_json = requests.get(sv, timeout=int(settings.sonarr.http_timeout), verify=False, headers=headers).json()
if 'version' in sonarr_json: if 'version' in sonarr_json:
sonarr_version = sonarr_json['version'] sonarr_version = sonarr_json['version']
else: else:
@ -37,7 +37,7 @@ class GetSonarrInfo:
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
try: try:
sv = url_sonarr() + "/api/v3/system/status?apikey=" + settings.sonarr.apikey sv = url_sonarr() + "/api/v3/system/status?apikey=" + settings.sonarr.apikey
sonarr_version = requests.get(sv, timeout=60, verify=False, headers=headers).json()['version'] sonarr_version = requests.get(sv, timeout=int(settings.sonarr.http_timeout), verify=False, headers=headers).json()['version']
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
logging.debug('BAZARR cannot get Sonarr version') logging.debug('BAZARR cannot get Sonarr version')
sonarr_version = 'unknown' sonarr_version = 'unknown'

@ -18,6 +18,6 @@ def notify_sonarr(sonarr_series_id):
'name': 'RescanSeries', 'name': 'RescanSeries',
'seriesId': int(sonarr_series_id) 'seriesId': int(sonarr_series_id)
} }
requests.post(url, json=data, timeout=60, verify=False, headers=headers) requests.post(url, json=data, timeout=int(settings.sonarr.http_timeout), verify=False, headers=headers)
except Exception: except Exception:
logging.exception('BAZARR cannot notify Sonarr') logging.exception('BAZARR cannot notify Sonarr')

@ -22,7 +22,7 @@ def get_sonarr_rootfolder():
url_sonarr_api_rootfolder = url_sonarr() + "/api/v3/rootfolder?apikey=" + apikey_sonarr url_sonarr_api_rootfolder = url_sonarr() + "/api/v3/rootfolder?apikey=" + apikey_sonarr
try: try:
rootfolder = requests.get(url_sonarr_api_rootfolder, timeout=60, verify=False, headers=headers) rootfolder = requests.get(url_sonarr_api_rootfolder, timeout=int(settings.sonarr.http_timeout), verify=False, headers=headers)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
logging.exception("BAZARR Error trying to get rootfolder from Sonarr. Connection Error.") logging.exception("BAZARR Error trying to get rootfolder from Sonarr. Connection Error.")
return [] return []

@ -22,7 +22,7 @@ def get_profile_list():
url_sonarr_api_series = url_sonarr() + "/api/v3/languageprofile?apikey=" + apikey_sonarr url_sonarr_api_series = url_sonarr() + "/api/v3/languageprofile?apikey=" + apikey_sonarr
try: try:
profiles_json = requests.get(url_sonarr_api_series, timeout=60, verify=False, headers=headers) profiles_json = requests.get(url_sonarr_api_series, timeout=int(settings.sonarr.http_timeout), verify=False, headers=headers)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
logging.exception("BAZARR Error trying to get profiles from Sonarr. Connection Error.") logging.exception("BAZARR Error trying to get profiles from Sonarr. Connection Error.")
return None return None
@ -55,7 +55,7 @@ def get_tags():
url_sonarr_api_series = url_sonarr() + "/api/v3/tag?apikey=" + apikey_sonarr url_sonarr_api_series = url_sonarr() + "/api/v3/tag?apikey=" + apikey_sonarr
try: try:
tagsDict = requests.get(url_sonarr_api_series, timeout=60, verify=False, headers=headers) tagsDict = requests.get(url_sonarr_api_series, timeout=int(settings.sonarr.http_timeout), verify=False, headers=headers)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
logging.exception("BAZARR Error trying to get tags from Sonarr. Connection Error.") logging.exception("BAZARR Error trying to get tags from Sonarr. Connection Error.")
return [] return []
@ -73,7 +73,7 @@ def get_series_from_sonarr_api(url, apikey_sonarr, sonarr_series_id=None):
url_sonarr_api_series = url + "/api/{0}series/{1}?apikey={2}".format( url_sonarr_api_series = url + "/api/{0}series/{1}?apikey={2}".format(
'' if get_sonarr_info.is_legacy() else 'v3/', sonarr_series_id if sonarr_series_id else "", apikey_sonarr) '' if get_sonarr_info.is_legacy() else 'v3/', sonarr_series_id if sonarr_series_id else "", apikey_sonarr)
try: try:
r = requests.get(url_sonarr_api_series, timeout=60, verify=False, headers=headers) r = requests.get(url_sonarr_api_series, timeout=int(settings.sonarr.http_timeout), verify=False, headers=headers)
r.raise_for_status() r.raise_for_status()
except requests.exceptions.HTTPError as e: except requests.exceptions.HTTPError as e:
if e.response.status_code: if e.response.status_code:
@ -108,7 +108,7 @@ def get_episodes_from_sonarr_api(url, apikey_sonarr, series_id=None, episode_id=
return return
try: try:
r = requests.get(url_sonarr_api_episode, timeout=60, verify=False, headers=headers) r = requests.get(url_sonarr_api_episode, timeout=int(settings.sonarr.http_timeout), verify=False, headers=headers)
r.raise_for_status() r.raise_for_status()
except requests.exceptions.HTTPError: except requests.exceptions.HTTPError:
logging.exception("BAZARR Error trying to get episodes from Sonarr. Http error.") logging.exception("BAZARR Error trying to get episodes from Sonarr. Http error.")
@ -136,7 +136,7 @@ def get_episodesFiles_from_sonarr_api(url, apikey_sonarr, series_id=None, episod
return return
try: try:
r = requests.get(url_sonarr_api_episodeFiles, timeout=60, verify=False, headers=headers) r = requests.get(url_sonarr_api_episodeFiles, timeout=int(settings.sonarr.http_timeout), verify=False, headers=headers)
r.raise_for_status() r.raise_for_status()
except requests.exceptions.HTTPError: except requests.exceptions.HTTPError:
logging.exception("BAZARR Error trying to get episodeFiles from Sonarr. Http error.") logging.exception("BAZARR Error trying to get episodeFiles from Sonarr. Http error.")

@ -9,11 +9,13 @@ import {
Number, Number,
PathMappingTable, PathMappingTable,
Section, Section,
Selector,
Slider, Slider,
Text, Text,
URLTestButton, URLTestButton,
} from "../components"; } from "../components";
import { moviesEnabledKey } from "../keys"; import { moviesEnabledKey } from "../keys";
import { timeoutOptions } from "./options";
const SettingsRadarrView: FunctionComponent = () => { const SettingsRadarrView: FunctionComponent = () => {
return ( return (
@ -35,6 +37,11 @@ const SettingsRadarrView: FunctionComponent = () => {
onSubmit: (v) => "/" + v, onSubmit: (v) => "/" + v,
}} }}
></Text> ></Text>
<Selector
label="HTTP Timeout"
options={timeoutOptions}
settingKey="settings-radarr-http_timeout"
></Selector>
<Text label="API Key" settingKey="settings-radarr-apikey"></Text> <Text label="API Key" settingKey="settings-radarr-apikey"></Text>
<Check label="SSL" settingKey="settings-radarr-ssl"></Check> <Check label="SSL" settingKey="settings-radarr-ssl"></Check>
<URLTestButton category="radarr"></URLTestButton> <URLTestButton category="radarr"></URLTestButton>

@ -0,0 +1,10 @@
import { SelectorOption } from "@/components";
export const timeoutOptions: SelectorOption<number>[] = [
{ label: "60", value: 60 },
{ label: "120", value: 120 },
{ label: "180", value: 180 },
{ label: "240", value: 240 },
{ label: "300", value: 300 },
{ label: "600", value: 600 },
];

@ -10,12 +10,14 @@ import {
Number, Number,
PathMappingTable, PathMappingTable,
Section, Section,
Selector,
Slider, Slider,
Text, Text,
URLTestButton, URLTestButton,
} from "../components"; } from "../components";
import { seriesEnabledKey } from "../keys"; import { seriesEnabledKey } from "../keys";
import { seriesTypeOptions } from "../options"; import { seriesTypeOptions } from "../options";
import { timeoutOptions } from "./options";
const SettingsSonarrView: FunctionComponent = () => { const SettingsSonarrView: FunctionComponent = () => {
return ( return (
@ -37,6 +39,11 @@ const SettingsSonarrView: FunctionComponent = () => {
onSubmit: (v) => "/" + v, onSubmit: (v) => "/" + v,
}} }}
></Text> ></Text>
<Selector
label="HTTP Timeout"
options={timeoutOptions}
settingKey="settings-sonarr-http_timeout"
></Selector>
<Text label="API Key" settingKey="settings-sonarr-apikey"></Text> <Text label="API Key" settingKey="settings-sonarr-apikey"></Text>
<Check label="SSL" settingKey="settings-sonarr-ssl"></Check> <Check label="SSL" settingKey="settings-sonarr-ssl"></Check>
<URLTestButton category="sonarr"></URLTestButton> <URLTestButton category="sonarr"></URLTestButton>

@ -0,0 +1,10 @@
import { SelectorOption } from "@/components";
export const timeoutOptions: SelectorOption<number>[] = [
{ label: "60", value: 60 },
{ label: "120", value: 120 },
{ label: "180", value: 180 },
{ label: "240", value: 240 },
{ label: "300", value: 300 },
{ label: "600", value: 600 },
];
Loading…
Cancel
Save