From e4442c8a959e56d4b652db1cc57f44e7d1923311 Mon Sep 17 00:00:00 2001 From: Jono Yang Date: Fri, 18 Mar 2022 15:52:58 -0700 Subject: [PATCH] Properly name field when processing licenses #504 * Use .get() method when getting JSON results #503 Signed-off-by: Jono Yang --- src/attributecode/api.py | 2 +- src/attributecode/attrib.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/attributecode/api.py b/src/attributecode/api.py index 6521536e..0ca7b9ee 100644 --- a/src/attributecode/api.py +++ b/src/attributecode/api.py @@ -60,7 +60,7 @@ def request_license_data(api_url, api_key, license_key): response_content = response.read().decode('utf-8') # FIXME: this should be an ordered dict license_data = json.loads(response_content) - if not license_data['results']: + if not license_data.get('results', []): msg = u"Invalid 'license': %s" % license_key errors.append(Error(ERROR, msg)) except HTTPError as http_e: diff --git a/src/attributecode/attrib.py b/src/attributecode/attrib.py index 63c16181..c960f897 100644 --- a/src/attributecode/attrib.py +++ b/src/attributecode/attrib.py @@ -172,7 +172,7 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score, lic_name_expression = ' '.join(lic_name_expression_list) # Add the license name expression string into the about object as a custom field - custom_field = StringField(name=name, value=lic_name_expression, present=True) + custom_field = StringField(name='license_name_expression', value=lic_name_expression, present=True) setattr(about, 'license_name_expression', custom_field) # Sort the about objects by name