summaryrefslogtreecommitdiff
path: root/searx/exceptions.py
diff options
context:
space:
mode:
authorLéon Tiekötter <leon@tiekoetter.com>2022-11-21 23:55:04 +0100
committerAlexandre Flament <alex@al-f.net>2023-01-15 09:00:32 +0000
commit0cedb1c6d8d38c911176cab954d858fe937cef71 (patch)
treebf76db64f14e00515bd7fd64aa73e1cfab902bf5 /searx/exceptions.py
parentb720a495f0cc5372d07ed68e0d8a5ffa89a14b51 (diff)
downloadsearxng-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/exceptions.py')
-rw-r--r--searx/exceptions.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/searx/exceptions.py b/searx/exceptions.py
index 43c8bab40..af81bfb23 100644
--- a/searx/exceptions.py
+++ b/searx/exceptions.py
@@ -69,11 +69,19 @@ class SearxEngineAPIException(SearxEngineResponseException):
class SearxEngineAccessDeniedException(SearxEngineResponseException):
"""The website is blocking the access"""
- def __init__(self, suspended_time=24 * 3600, message='Access denied'):
+ SUSPEND_TIME_SETTING = "search.suspended_times.SearxEngineAccessDenied"
+
+ def __init__(self, suspended_time=None, message='Access denied'):
+ suspended_time = suspended_time or self._get_default_suspended_time()
super().__init__(message + ', suspended_time=' + str(suspended_time))
self.suspended_time = suspended_time
self.message = message
+ def _get_default_suspended_time(self):
+ from searx import get_setting
+
+ return get_setting(self.SUSPEND_TIME_SETTING)
+
class SearxEngineCaptchaException(SearxEngineAccessDeniedException):
"""The website has returned a CAPTCHA
@@ -81,7 +89,9 @@ class SearxEngineCaptchaException(SearxEngineAccessDeniedException):
By default, searx stops sending requests to this engine for 1 day.
"""
- def __init__(self, suspended_time=24 * 3600, message='CAPTCHA'):
+ SUSPEND_TIME_SETTING = "search.suspended_times.SearxEngineCaptcha"
+
+ def __init__(self, suspended_time=None, message='CAPTCHA'):
super().__init__(message=message, suspended_time=suspended_time)
@@ -91,7 +101,9 @@ class SearxEngineTooManyRequestsException(SearxEngineAccessDeniedException):
By default, searx stops sending requests to this engine for 1 hour.
"""
- def __init__(self, suspended_time=3600, message='Too many request'):
+ SUSPEND_TIME_SETTING = "search.suspended_times.SearxEngineTooManyRequests"
+
+ def __init__(self, suspended_time=None, message='Too many request'):
super().__init__(message=message, suspended_time=suspended_time)