From f69b22c45cf156dd935db583550d2134077435d1 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 7 Jul 2026 10:44:13 +0200 Subject: [PATCH] [fix] kagi: crashes when there are no results --- searx/engines/kagi.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/searx/engines/kagi.py b/searx/engines/kagi.py index 63ec64c17..85cc62c98 100644 --- a/searx/engines/kagi.py +++ b/searx/engines/kagi.py @@ -139,9 +139,13 @@ def response(resp: "SXNG_Response") -> EngineResults: if kagi_categ in ("images", "videos"): # the JSON key is "image" for "images" and "video" for "videos" - json_results = json_data["data"][kagi_categ[:-1]] + json_results = json_data["data"].get(kagi_categ[:-1]) else: - json_results = json_data["data"][kagi_categ] + json_results = json_data["data"].get(kagi_categ) + + # if no results were found, the response doesn't contain the results field + if not json_results: + return res for result in json_results: published_date: datetime | None = None