From ca8f3f9fd2ae21360549eb80a76d0291d41f96c5 Mon Sep 17 00:00:00 2001 From: morpheus65535 Date: Mon, 6 Dec 2021 19:31:10 -0500 Subject: [PATCH] Fixed throttled providers badges in UI throwing exception. #1631 --- bazarr/api/badges/badges.py | 2 +- bazarr/get_providers.py | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bazarr/api/badges/badges.py b/bazarr/api/badges/badges.py index 4d1b6ddf2..e9d6561f3 100644 --- a/bazarr/api/badges/badges.py +++ b/bazarr/api/badges/badges.py @@ -34,7 +34,7 @@ class Badges(Resource): .where(reduce(operator.and_, movies_conditions))\ .count() - throttled_providers = len(eval(str(get_throttled_providers()))) + throttled_providers = len(get_throttled_providers()) health_issues = len(get_health_issues()) diff --git a/bazarr/get_providers.py b/bazarr/get_providers.py index ab3974c4b..bf230931e 100644 --- a/bazarr/get_providers.py +++ b/bazarr/get_providers.py @@ -315,12 +315,15 @@ def reset_throttled_providers(): def get_throttled_providers(): providers = {} - if os.path.exists(os.path.join(args.config_dir, 'config', 'throttled_providers.dat')): - with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'throttled_providers.dat')), 'r') as handle: - providers = handle.read() - if not providers: + try: + if os.path.exists(os.path.join(args.config_dir, 'config', 'throttled_providers.dat')): + with open(os.path.normpath(os.path.join(args.config_dir, 'config', 'throttled_providers.dat')), 'r') as \ + handle: + providers = ast.literal_eval(handle.read()) + except (OSError, ValueError): providers = {} - return providers + finally: + return providers def set_throttled_providers(data): @@ -329,11 +332,11 @@ def set_throttled_providers(data): try: - tp = eval(str(get_throttled_providers())) + tp = get_throttled_providers() if not isinstance(tp, dict): raise ValueError('tp should be a dict') except Exception: logging.error("Invalid content in throttled_providers.dat. Resetting") # set empty content in throttled_providers.dat set_throttled_providers('') - tp = eval(str(get_throttled_providers())) + tp = get_throttled_providers()