on master help sign in
Merge pull request #2354 from dalf/fix-wikipedia
cdceec1Alexandre Flament
docs/dev/engine_overview.rst+4−3
@@ -134,9 +134,9 @@ The function ``def request(query, params):`` always returns the ``params``
134variable. Inside searx, the following paramters can be used to specify a search
134variable. Inside searx, the following paramters can be used to specify a search
135request:
135request:
136
136
137−================== =========== ========================================================================
137+================== =========== ==========================================================================
138argument type information
138argument type information
139−================== =========== ========================================================================
139+================== =========== ==========================================================================
140url string requested url
140url string requested url
141method string HTTP request method
141method string HTTP request method
142headers set HTTP header information
142headers set HTTP header information
@@ -145,7 +145,8 @@ cookies set HTTP cookies
145verify boolean Performing SSL-Validity check
145verify boolean Performing SSL-Validity check
146max_redirects int maximum redirects, hard limit
146max_redirects int maximum redirects, hard limit
147soft_max_redirects int maximum redirects, soft limit. Record an error but don't stop the engine
147soft_max_redirects int maximum redirects, soft limit. Record an error but don't stop the engine
148−================== =========== ========================================================================
148+raise_for_status bool True by default: raise an exception if the HTTP code of response is >= 300
149+================== =========== ==========================================================================
149
150
150
151
151example code
152example code
searx/engines/wikipedia.py+3−1
@@ -37,13 +37,15 @@ def request(query, params):
37 language=url_lang(params['language']))
37 language=url_lang(params['language']))
38
38
39 params['headers']['User-Agent'] = searx_useragent()
39 params['headers']['User-Agent'] = searx_useragent()
40+ params['raise_for_status'] = False
41+ params['soft_max_redirects'] = 2
40
42
41 return params
43 return params
42
44
43
45
44# get response from search-request
46# get response from search-request
45def response(resp):
47def response(resp):
46− if not resp.ok:
48+ if resp.status_code == 404:
47 return []
49 return []
48
50
49 results = []
51 results = []
searx/search.py+4−2
@@ -143,7 +143,8 @@ def send_http_request(engine, request_params):
143 response = req(request_params['url'], **request_args)
143 response = req(request_params['url'], **request_args)
144
144
145 # check HTTP status
145 # check HTTP status
146+ if request_params.get('raise_for_status'):
146− response.raise_for_status()
147+ response.raise_for_status()
147
148
148 # check soft limit of the redirect count
149 # check soft limit of the redirect count
149 if len(response.history) > soft_max_redirects:
150 if len(response.history) > soft_max_redirects:
@@ -340,7 +341,8 @@ def default_request_params():
340 'url': '',
341 'url': '',
341 'cookies': {},
342 'cookies': {},
342 'verify': True,
343 'verify': True,
343− 'auth': None
344+ 'auth': None,
345+ 'raise_for_status': True
344 }
346 }
345
347
346
348