diff options
author | Léon Tiekötter <leon@tiekoetter.com> | 2022-11-21 23:55:04 +0100 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2023-01-15 09:00:32 +0000 |
commit | 0cedb1c6d8d38c911176cab954d858fe937cef71 (patch) | |
tree | bf76db64f14e00515bd7fd64aa73e1cfab902bf5 /searx/network | |
parent | b720a495f0cc5372d07ed68e0d8a5ffa89a14b51 (diff) | |
download | searxng-0cedb1c6d8d38c911176cab954d858fe937cef71.tar.gz searxng-0cedb1c6d8d38c911176cab954d858fe937cef71.zip |
Add search.suspended_times settings
Make suspended_time changeable in settings.yml
Allow different values to be set for different exceptions.
Co-authored-by: Alexandre Flament <alex@al-f.net>
Diffstat (limited to 'searx/network')
-rw-r--r-- | searx/network/raise_for_httperror.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/searx/network/raise_for_httperror.py b/searx/network/raise_for_httperror.py index 414074977..7fc2b7877 100644 --- a/searx/network/raise_for_httperror.py +++ b/searx/network/raise_for_httperror.py @@ -9,6 +9,7 @@ from searx.exceptions import ( SearxEngineTooManyRequestsException, SearxEngineAccessDeniedException, ) +from searx import get_setting def is_cloudflare_challenge(resp): @@ -33,15 +34,22 @@ def raise_for_cloudflare_captcha(resp): if is_cloudflare_challenge(resp): # https://support.cloudflare.com/hc/en-us/articles/200170136-Understanding-Cloudflare-Challenge-Passage-Captcha- # suspend for 2 weeks - raise SearxEngineCaptchaException(message='Cloudflare CAPTCHA', suspended_time=3600 * 24 * 15) + raise SearxEngineCaptchaException( + message='Cloudflare CAPTCHA', suspended_time=get_setting('search.suspended_times.cf_SearxEngineCaptcha') + ) if is_cloudflare_firewall(resp): - raise SearxEngineAccessDeniedException(message='Cloudflare Firewall', suspended_time=3600 * 24) + raise SearxEngineAccessDeniedException( + message='Cloudflare Firewall', + suspended_time=get_setting('search.suspended_times.cf_SearxEngineAccessDenied'), + ) def raise_for_recaptcha(resp): if resp.status_code == 503 and '"https://www.google.com/recaptcha/' in resp.text: - raise SearxEngineCaptchaException(message='ReCAPTCHA', suspended_time=3600 * 24 * 7) + raise SearxEngineCaptchaException( + message='ReCAPTCHA', suspended_time=get_setting('search.suspended_times.recaptcha_SearxEngineCaptcha') + ) def raise_for_captcha(resp): |