[fix] baidu captcha detection (#5111)

Add Baidu Captcha detection to reduce `JSONDecodeError` error

Baidu will redirect to `wappass.baidu.com` and return a captcha challenge.
Current behavior will get the data from `wappass.baidu.com` then return a
`json.decoder.JSONDecodeError` error.
This commit is contained in:
Zhijie He 2025-08-12 21:18:46 +08:00 committed by GitHub
parent 6cccb46f2b
commit 6b1516d6ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,7 +13,7 @@ from html import unescape
import time
import json
from searx.exceptions import SearxEngineAPIException
from searx.exceptions import SearxEngineAPIException, SearxEngineCaptchaException
from searx.utils import html_to_text
about = {
@ -89,10 +89,14 @@ def request(query, params):
query_params["paramList"] += f",timestamp_range={past}-{now}"
params["url"] = f"{query_url}?{urlencode(query_params)}"
params["allow_redirects"] = False
return params
def response(resp):
# Detect Baidu Captcha, it will redirect to wappass.baidu.com
if 'wappass.baidu.com/static/captcha' in resp.headers.get('Location', ''):
raise SearxEngineCaptchaException()
text = resp.text
if baidu_category == 'images':