From 22c64b8d394b680c7ea96be25f36dad14126420a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 12 Oct 2026 19:22:07 +0200 Subject: [PATCH] [fix] xprivo: crashes when parsing response --- searx/engines/xprivo.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/searx/engines/xprivo.py b/searx/engines/xprivo.py index 8abb4474a..5463accd6 100644 --- a/searx/engines/xprivo.py +++ b/searx/engines/xprivo.py @@ -4,6 +4,7 @@ import json import typing as t +from searx.exceptions import SearxEngineAPIException from searx.result_types import EngineResults if t.TYPE_CHECKING: @@ -58,8 +59,15 @@ def response(resp: "SXNG_Response") -> EngineResults: res = EngineResults() # response is a Server-Side Events (SSE) stream - data_raw = resp.text.split("\n", 1)[0].removeprefix("data: ") - data = json.loads(data_raw) + # we search for a JSON object with the "results" key + data_parts = [line for line in resp.text.split("\n") if line] + for data_raw in data_parts: + data_raw = data_raw.removeprefix("data: ") + data: dict[str, t.Any] = json.loads(data_raw) + if "results" in data: + break + else: + raise SearxEngineAPIException("no results in response") result: dict[str, str] for result in data["results"]: