diff options
| author | Zhijie He <hezhijie0327@hotmail.com> | 2025-08-12 21:18:46 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-12 15:18:46 +0200 |
| commit | 6b1516d6adc88f17e06fe115c3aff69bfcad4579 (patch) | |
| tree | 6ddbdbcd440a719ac14ef3afce0948466418903d | |
| parent | 6cccb46f2b2839daee13c5d12e86a7987a22e6cd (diff) | |
[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.
| -rw-r--r-- | searx/engines/baidu.py | 6 |
1 files changed, 5 insertions, 1 deletions
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': |