From 6b1516d6adc88f17e06fe115c3aff69bfcad4579 Mon Sep 17 00:00:00 2001 From: Zhijie He Date: Tue, 12 Aug 2025 21:18:46 +0800 Subject: [PATCH] [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. --- searx/engines/baidu.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/searx/engines/baidu.py b/searx/engines/baidu.py index 29c9c0e4d..57d1ed444 100644 --- a/searx/engines/baidu.py +++ b/searx/engines/baidu.py @@ -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':