diff options
| author | Markus Heiser <markus.heiser@darmarit.de> | 2025-01-28 16:51:07 +0100 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarIT.de> | 2025-01-29 05:04:41 +0100 |
| commit | df3344e5d5fdfd2425324d5e10e8c8e5104963b0 (patch) | |
| tree | ce9af594706b1f81eba7349b58b6f349fe4ffb87 /searx/webutils.py | |
| parent | 906b9e7d4c87dcb7ded4ef1248e9569caf408cc7 (diff) | |
[fix] JSON & CSV format return error 500
For CSV and JSON output, the LegacyResult and the Result objects needs to be
converted to a python dictionary.
Closes: https://github.com/searxng/searxng/issues/4244
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/webutils.py')
| -rw-r--r-- | searx/webutils.py | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/searx/webutils.py b/searx/webutils.py index c58b981f6..6e49e3830 100644 --- a/searx/webutils.py +++ b/searx/webutils.py @@ -123,17 +123,18 @@ def write_csv_response(csv: CSVWriter, rc: ResultContainer) -> None: # pylint: """ - results = rc.get_ordered_results() keys = ('title', 'url', 'content', 'host', 'engine', 'score', 'type') csv.writerow(keys) - for row in results: + for res in rc.get_ordered_results(): + row = res.as_dict() row['host'] = row['parsed_url'].netloc row['type'] = 'result' csv.writerow([row.get(key, '') for key in keys]) for a in rc.answers: - row = {'title': a, 'type': 'answer'} + row = a.as_dict() + row['host'] = row['parsed_url'].netloc csv.writerow([row.get(key, '') for key in keys]) for a in rc.suggestions: @@ -158,18 +159,17 @@ class JSONEncoder(json.JSONEncoder): # pylint: disable=missing-class-docstring def get_json_response(sq: SearchQuery, rc: ResultContainer) -> str: """Returns the JSON string of the results to a query (``application/json``)""" - results = rc.number_of_results - x = { + data = { 'query': sq.query, - 'number_of_results': results, - 'results': rc.get_ordered_results(), - 'answers': list(rc.answers), + 'number_of_results': rc.number_of_results, + 'results': [_.as_dict() for _ in rc.get_ordered_results()], + 'answers': [_.as_dict() for _ in rc.answers], 'corrections': list(rc.corrections), 'infoboxes': rc.infoboxes, 'suggestions': list(rc.suggestions), 'unresponsive_engines': get_translated_errors(rc.unresponsive_engines), } - response = json.dumps(x, cls=JSONEncoder) + response = json.dumps(data, cls=JSONEncoder) return response |