[fix] heexy: use cookies for cacheft token

Heexy now passes the cacheft token via cookies and no
longer via HTTP headers.

Hence, the engine is broken without that change.
This commit is contained in:
Bnyro
2026-07-08 20:53:08 +02:00
parent da6a230413
commit 3b573e0f89

View File

@@ -13,13 +13,12 @@ It seems to use Bing internally, as the image thumbnails are loaded from Bing.
from urllib.parse import urlencode from urllib.parse import urlencode
import typing as t import typing as t
from lxml import html
from searx.enginelib import EngineCache from searx.enginelib import EngineCache
from searx.network import get from searx.network import get
from searx.exceptions import SearxEngineAPIException, SearxEngineAccessDeniedException from searx.exceptions import SearxEngineAPIException, SearxEngineAccessDeniedException
from searx.result_types import EngineResults from searx.result_types import EngineResults
from searx.utils import eval_xpath, extract_text, gen_useragent from searx.utils import gen_useragent
if t.TYPE_CHECKING: if t.TYPE_CHECKING:
from searx.extended_types import SXNG_Response from searx.extended_types import SXNG_Response
@@ -73,8 +72,7 @@ def _get_api_token(query: str) -> str:
if not resp.ok: if not resp.ok:
raise SearxEngineAPIException("failed to obtain request token: invalid response code") raise SearxEngineAPIException("failed to obtain request token: invalid response code")
doc = html.fromstring(resp.text) token = resp.cookies["cacheft"]
token = extract_text(eval_xpath(doc, "//html/@data-cacheft"))
if not token: if not token:
raise SearxEngineAPIException("failed to obtain request token: no token found") raise SearxEngineAPIException("failed to obtain request token: no token found")
@@ -92,8 +90,9 @@ def request(query: str, params: "OnlineParams") -> None:
args["lang"] = params["searxng_locale"].split("-")[0] args["lang"] = params["searxng_locale"].split("-")[0]
params["url"] = f"{api_url}/search/{heexy_categ}?{urlencode(args)}" params["url"] = f"{api_url}/search/{heexy_categ}?{urlencode(args)}"
params["headers"]["X-Data-Cacheft"] = _get_api_token(query)
params["headers"]["Origin"] = api_url params["headers"]["Origin"] = api_url
params["cookies"]["cacheft"] = _get_api_token(query)
def response(resp: "SXNG_Response"): def response(resp: "SXNG_Response"):