diff --git a/searx/network/raise_for_httperror.py b/searx/network/raise_for_httperror.py index bd12df9a9d94270e9e14c54cc572ee19e6644431..ef60d405c074a0b51e0525f836f47b9b8a519915 100644 --- a/searx/network/raise_for_httperror.py +++ b/searx/network/raise_for_httperror.py @@ -2,7 +2,7 @@ """ Raise exception for an HTTP response is an error. """ -from searx.exceptions import (SearxEngineCaptchaException, SearxEngineTooManyRequestsException, +from searx.exceptions import (SearxEngineAPIException, SearxEngineCaptchaException, SearxEngineTooManyRequestsException, SearxEngineAccessDeniedException) @@ -63,4 +63,7 @@ def raise_for_httperror(resp): suspended_time=3600 * 24) if resp.status_code == 429: raise SearxEngineTooManyRequestsException() + if resp.status_code == 404: + message = f'(404) Resource not found for "{resp.url.host}". Are you sure the API endpoint is valid?' + raise SearxEngineAPIException(message) resp.raise_for_status() diff --git a/searx/search/processors/online.py b/searx/search/processors/online.py index 66719ea9b7bfe37698a2b67d4b7d73f14987e08a..f52084d45fa9719bae6f515365083f88e525217d 100644 --- a/searx/search/processors/online.py +++ b/searx/search/processors/online.py @@ -15,6 +15,7 @@ from searx.exceptions import (SearxEngineAccessDeniedException, SearxEngineCaptc from searx.metrology.error_recorder import record_exception, record_error from searx.search.processors.abstract import EngineProcessor +from urllib.parse import urlparse logger = logger.getChild('search.processor.online') @@ -175,9 +176,13 @@ class OnlineProcessor(EngineProcessor): elif (issubclass(e.__class__, (httpx.HTTPError, httpx.StreamError))): result_container.add_unresponsive_engine(self.engine_name, 'HTTP error') # other requests exception + response_url = urlparse(str(e.response.url)) + status_code = e.response.status_code + hostname = response_url.hostname logger.exception("engine {0} : requests exception" - "(search duration : {1} s, timeout: {2} s) : {3}" - .format(self.engine_name, engine_time, timeout_limit, e)) + "(search duration : {1} s, timeout: {2} s) : " + "Status code {3} while requesting {4}" + .format(self.engine_name, engine_time, timeout_limit, status_code, hostname)) http_exception = True elif (issubclass(e.__class__, SearxEngineCaptchaException)): result_container.add_unresponsive_engine(self.engine_name, 'CAPTCHA required')