[upd] wikipedia engine: return an empty result on query with illegal characters
on some queries (like an IT error message), wikipedia returns an HTTP error 400.
this commit returns an empty result instead of showing an error to the user.
commit7d6e69e2f9c1efd76616af0f58d0d7313a338c47
authorAlexandre Flament <alex@al-f.net>
dateThu 11 Feb 2021, 12:29 (6 years ago)
parent436d366
searx/engines/wikipedia.py+11
@@ -56,6 +56,17 @@ def request(query, params):
5656def response(resp):
5757 if resp.status_code == 404:
5858 return []
59+
60+ if resp.status_code == 400:
61+ try:
62+ api_result = loads(resp.text)
63+ except:
64+ pass
65+ else:
66+ if api_result['type'] == 'https://mediawiki.org/wiki/HyperSwitch/errors/bad_request' \
67+ and api_result['detail'] == 'title-invalid-characters':
68+ return []
69+
5970 raise_for_httperror(resp)
6071
6172 results = []