2 Commits

Author SHA1 Message Date
Bnyro
58e02a01ae [fix] tusksearch: fix engine blocked by bot protection
Changes:
- the `embed.js` request now requires a user agent header
- we include a user agent in the "actual" request (I dropped it by accident)
- we only send the first 4 decimal places of the location
  instead of 7+ (not required, but harder to detect)
2026-07-14 20:32:31 +02:00
Bnyro
7fa9f16225 [fix] heexy: blocked by cloudflare 2026-07-14 20:32:18 +02:00
2 changed files with 14 additions and 10 deletions

View File

@@ -68,7 +68,9 @@ def _get_api_token(query: str) -> str:
if cached_token: if cached_token:
return cached_token return cached_token
resp = get(f"{base_url}/search?q={query}", headers={"User-Agent": gen_useragent()}) resp = get(
f"{base_url}/search?q={query}", headers={"User-Agent": gen_useragent(), "Accept-Language": "en-US,en:q=0.9"}
)
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")
@@ -76,7 +78,7 @@ def _get_api_token(query: str) -> str:
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")
CACHE.set("token", token) CACHE.set("token", token, expire=3 * 60)
return token return token

View File

@@ -13,7 +13,7 @@ from dateutil import parser
from searx.exceptions import SearxEngineAPIException from searx.exceptions import SearxEngineAPIException
from searx.network import get from searx.network import get
from searx.utils import html_to_text from searx.utils import gen_useragent, html_to_text
from searx.result_types import EngineResults from searx.result_types import EngineResults
if t.TYPE_CHECKING: if t.TYPE_CHECKING:
@@ -52,7 +52,7 @@ def _obtain_x_sid() -> tuple[str, str]:
The header key is usually called `x-sid-{UUIDv4}`, and the value is The header key is usually called `x-sid-{UUIDv4}`, and the value is
usually a plain UUIDv4 (but a different one than in the header key). usually a plain UUIDv4 (but a different one than in the header key).
""" """
resp = get(f"{api_url}/revcontent/embed.js") resp = get(f"{api_url}/revcontent/embed.js", headers={"User-Agent": gen_useragent()})
if not resp.ok: if not resp.ok:
raise SearxEngineAPIException("failed to obtain request x-sid token") raise SearxEngineAPIException("failed to obtain request x-sid token")
@@ -89,12 +89,14 @@ def request(query: str, params: "OnlineParams") -> None:
params["url"] = f"{api_url}/Search/Web?{urlencode(args)}" params["url"] = f"{api_url}/Search/Web?{urlencode(args)}"
x_sid_header, x_sid_value = _obtain_x_sid() x_sid_header, x_sid_value = _obtain_x_sid()
params["headers"] = { params["headers"].update(
x_sid_header: x_sid_value, {
# required - we send a random longitude and latitude instead of the actual user location x_sid_header: x_sid_value,
'x-lon': str(random.random() * 90), # required - we send a random longitude and latitude instead of the actual user location
'x-lat': str(random.random() * 90), "x-lon": str(round(random.random() * 90, 4)),
} "x-lat": str(round(random.random() * 90, 4)),
}
)
def response(resp: "SXNG_Response"): def response(resp: "SXNG_Response"):