From 7d6e69e2f9c1efd76616af0f58d0d7313a338c47 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Thu, 11 Feb 2021 12:29:21 +0100 Subject: [PATCH] [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. --- searx/engines/wikipedia.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/searx/engines/wikipedia.py b/searx/engines/wikipedia.py index c8e589e6..2adfefa6 100644 --- a/searx/engines/wikipedia.py +++ b/searx/engines/wikipedia.py @@ -56,6 +56,17 @@ def request(query, params): def response(resp): if resp.status_code == 404: return [] + + if resp.status_code == 400: + try: + api_result = loads(resp.text) + except: + pass + else: + if api_result['type'] == 'https://mediawiki.org/wiki/HyperSwitch/errors/bad_request' \ + and api_result['detail'] == 'title-invalid-characters': + return [] + raise_for_httperror(resp) results = []