From c1facd3d878d1d5373df5a5f371d778af43b63ee Mon Sep 17 00:00:00 2001 From: Themis Zamani Date: Tue, 12 Apr 2022 10:23:16 +0300 Subject: [PATCH] Put a check for files. The script was throwing an error. CRITICAL: NameError("name 'files' is not defined",) --- check_b2share.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/check_b2share.py b/check_b2share.py index a1db093..1aea6e4 100755 --- a/check_b2share.py +++ b/check_b2share.py @@ -149,13 +149,14 @@ def get_dict_from_url(url, verify_tls_cert=False, verbosity=False): rec_with_files_url = None for hit in search_results['hits']['hits']: - # Check if there are files in the record - if len(hit['files']) > 0: - # NTS: Could throw KeyError if there is something - # seriously wrong or B2SHARE REST API responses have - # changed. - rec_with_files_url = hit['links']['self'] - break + if 'files' in hit: + # Check if there are files in the record + if len(hit['files']) > 0: + # NTS: Could throw KeyError if there is something + # seriously wrong or B2SHARE REST API responses have + # changed. + rec_with_files_url = hit['links']['self'] + break if rec_with_files_url: