From 968bc7d468b2a24ded48b4deeb76b216ddb9a350 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Thu, 1 Oct 2020 16:10:41 +0300 Subject: Make object JSON serializable * wqflask/wqflask/search_results.py (SearchResultPage.gen_search_result): Some of the items is self.trait_list are in bytes, and *json.loads* can't serialize bytes into JSON. --- wqflask/wqflask/search_results.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py index aa8f9e8f..ce836ce2 100644 --- a/wqflask/wqflask/search_results.py +++ b/wqflask/wqflask/search_results.py @@ -149,6 +149,10 @@ views.py). trait_dict['additive'] = "N/A" if this_trait.additive != "": trait_dict['additive'] = '%.3f' % this_trait.additive + # Convert any bytes in dict to a normal utf-8 string + for key in trait_dict.keys(): + if isinstance(trait_dict[key], bytes): + trait_dict[key] = trait_dict[key].decode('utf-8') trait_list.append(trait_dict) self.trait_list = json.dumps(trait_list) -- cgit v1.2.3