SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
[fix] wikipedia engine: don't raise an error when the query is not found
Alexandre Flamentf0054d67f11b
diff --git a/docs/dev/engine_overview.rst b/docs/dev/engine_overview.rstindex 0f58af765..0b5f9857f 100644--- a/docs/dev/engine_overview.rst+++ b/docs/dev/engine_overview.rst@@ -134,9 +134,9 @@ The function ``def request(query, params):`` always returns the ``params``variable. Inside searx, the following paramters can be used to specify a searchrequest:-================== =========== ========================================================================+================== =========== ==========================================================================argument type information-================== =========== ========================================================================+================== =========== ==========================================================================url string requested urlmethod string HTTP request methodheaders set HTTP header information@@ -145,7 +145,8 @@ cookies set HTTP cookiesverify boolean Performing SSL-Validity checkmax_redirects int maximum redirects, hard limitsoft_max_redirects int maximum redirects, soft limit. Record an error but don't stop the engine-================== =========== ========================================================================+raise_for_status bool True by default: raise an exception if the HTTP code of response is >= 300+================== =========== ==========================================================================example codediff --git a/searx/engines/wikipedia.py b/searx/engines/wikipedia.pyindex 620ec3c14..9fce170eb 100644--- a/searx/engines/wikipedia.py+++ b/searx/engines/wikipedia.py@@ -37,13 +37,15 @@ def request(query, params):language=url_lang(params['language']))params['headers']['User-Agent'] = searx_useragent()+ params['raise_for_status'] = False+ params['soft_max_redirects'] = 2return params# get response from search-requestdef response(resp):- if not resp.ok:+ if resp.status_code == 404:return []results = []diff --git a/searx/search.py b/searx/search.pyindex 8898f1576..8c2ad8d72 100644--- a/searx/search.py+++ b/searx/search.py@@ -143,7 +143,8 @@ def send_http_request(engine, request_params):response = req(request_params['url'], **request_args)# check HTTP status- response.raise_for_status()+ if request_params.get('raise_for_status'):+ response.raise_for_status()# check soft limit of the redirect countif len(response.history) > soft_max_redirects:@@ -340,7 +341,8 @@ def default_request_params():'url': '','cookies': {},'verify': True,- 'auth': None+ 'auth': None,+ 'raise_for_status': True}