mirror of
https://github.com/searxng/searxng.git
synced 2025-08-26 05:17:54 +02:00
[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:
parent
6cccb46f2b
commit
6b1516d6ad
1 changed files with 5 additions and 1 deletions
|
@ -13,7 +13,7 @@ from html import unescape
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from searx.exceptions import SearxEngineAPIException
|
from searx.exceptions import SearxEngineAPIException, SearxEngineCaptchaException
|
||||||
from searx.utils import html_to_text
|
from searx.utils import html_to_text
|
||||||
|
|
||||||
about = {
|
about = {
|
||||||
|
@ -89,10 +89,14 @@ def request(query, params):
|
||||||
query_params["paramList"] += f",timestamp_range={past}-{now}"
|
query_params["paramList"] += f",timestamp_range={past}-{now}"
|
||||||
|
|
||||||
params["url"] = f"{query_url}?{urlencode(query_params)}"
|
params["url"] = f"{query_url}?{urlencode(query_params)}"
|
||||||
|
params["allow_redirects"] = False
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|
||||||
def response(resp):
|
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
|
text = resp.text
|
||||||
if baidu_category == 'images':
|
if baidu_category == 'images':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue