Skip to content

Commit

Permalink
[fix] engine duden - don't raise exception on empty result list
Browse files Browse the repository at this point in the history
Duden expects a word in German, so with query "amazing" the site finds nothing
and respons a 404:

    httpx.HTTPStatusError: Client error '404 Not Found' for url\
      'https://www.duden.de/suchen/dudenonline/amazing'

[1] searxng#1543 (comment)

Suggested-by: @allendema [1]
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
  • Loading branch information
return42 committed Aug 20, 2022
1 parent 6f28a69 commit 77a0f33
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions searx/engines/duden.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from urllib.parse import quote, urljoin
from lxml import html
from searx.utils import extract_text, eval_xpath, eval_xpath_list, eval_xpath_getindex
from searx.network import raise_for_httperror

# about
about = {
Expand Down Expand Up @@ -47,6 +48,7 @@ def request(query, params):
# after the last page of results, spelling corrections are returned after a HTTP redirect
# whatever the page number is
params['soft_max_redirects'] = 1
params['raise_for_httperror'] = False
return params


Expand All @@ -56,6 +58,11 @@ def response(resp):
'''
results = []

if resp.status_code == 404:
return results

raise_for_httperror(resp)

dom = html.fromstring(resp.text)

number_of_results_element = eval_xpath_getindex(
Expand Down

0 comments on commit 77a0f33

Please sign in to comment.