diff options
author | Alexandre Flament <alex@al-f.net> | 2020-12-09 21:23:20 +0100 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2020-12-11 14:37:08 +0100 |
commit | d703119d3a313a406482b121ee94c6afee3bc307 (patch) | |
tree | 7834dc899b99db4ea3f9f81542e8e029bf5b7d04 /searx/exceptions.py | |
parent | 033f39bff7b3365256491014140e35aa1e974d4e (diff) | |
download | searxng-d703119d3a313a406482b121ee94c6afee3bc307.tar.gz searxng-d703119d3a313a406482b121ee94c6afee3bc307.zip |
[enh] add raise_for_httperror
check HTTP response:
* detect some comme CAPTCHA challenge (no solving). In this case the engine is suspended for long a time.
* otherwise raise HTTPError as before
the check is done in poolrequests.py (was before in search.py).
update qwant, wikipedia, wikidata to use raise_for_httperror instead of raise_for_status
Diffstat (limited to 'searx/exceptions.py')
-rw-r--r-- | searx/exceptions.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/searx/exceptions.py b/searx/exceptions.py index 82c1d76dc..67a282da2 100644 --- a/searx/exceptions.py +++ b/searx/exceptions.py @@ -64,8 +64,33 @@ class SearxEngineAPIException(SearxEngineResponseException): """The website has returned an application error""" -class SearxEngineCaptchaException(SearxEngineResponseException): - """The website has returned a CAPTCHA""" +class SearxEngineAccessDeniedException(SearxEngineResponseException): + """The website is blocking the access""" + + def __init__(self, suspended_time=24 * 3600, message='Access denied'): + super().__init__(message + ', suspended_time=' + str(suspended_time)) + self.suspended_time = suspended_time + self.message = message + + +class SearxEngineCaptchaException(SearxEngineAccessDeniedException): + """The website has returned a CAPTCHA + + By default, searx stops sending requests to this engine for 1 day. + """ + + def __init__(self, suspended_time=24 * 3600, message='CAPTCHA'): + super().__init__(message=message, suspended_time=suspended_time) + + +class SearxEngineTooManyRequestsException(SearxEngineAccessDeniedException): + """The website has returned a Too Many Request status code + + By default, searx stops sending requests to this engine for 1 hour. + """ + + def __init__(self, suspended_time=3600, message='Too many request'): + super().__init__(message=message, suspended_time=suspended_time) class SearxEngineXPathException(SearxEngineResponseException): |