diff options
author | Bnyro <bnyro@tutanota.com> | 2024-11-25 17:00:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-25 17:00:52 +0100 |
commit | 66f6495a2253e1c5ec9abae35640ce2a951250e2 (patch) | |
tree | 61a09706feffdea1f732067681391dbb84fcb0fb /searx/engines/duckduckgo_extra.py | |
parent | 5bf3fbc93b93cd415e1460877051854c76ae0a28 (diff) | |
download | searxng-66f6495a2253e1c5ec9abae35640ce2a951250e2.tar.gz searxng-66f6495a2253e1c5ec9abae35640ce2a951250e2.zip |
[fix] duckduckgo extra: crashes and returns no results
Diffstat (limited to 'searx/engines/duckduckgo_extra.py')
-rw-r--r-- | searx/engines/duckduckgo_extra.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/searx/engines/duckduckgo_extra.py b/searx/engines/duckduckgo_extra.py index b30574d6c..6b0d4b98c 100644 --- a/searx/engines/duckduckgo_extra.py +++ b/searx/engines/duckduckgo_extra.py @@ -4,16 +4,15 @@ DuckDuckGo Extra (images, videos, news) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ +from __future__ import annotations + from datetime import datetime from typing import TYPE_CHECKING from urllib.parse import urlencode from searx.utils import get_embeded_stream_url from searx.engines.duckduckgo import fetch_traits # pylint: disable=unused-import -from searx.engines.duckduckgo import ( - get_ddg_lang, - get_vqd, -) +from searx.engines.duckduckgo import get_ddg_lang, get_vqd from searx.enginelib.traits import EngineTraits if TYPE_CHECKING: @@ -48,15 +47,16 @@ search_path_map = {'images': 'i', 'videos': 'v', 'news': 'news'} def request(query, params): + eng_region: str = traits.get_region(params['searxng_locale'], traits.all_locale) # type: ignore # request needs a vqd argument - vqd = get_vqd(query) + vqd = get_vqd(query, eng_region, force_request=True) + if not vqd: # some search terms do not have results and therefore no vqd value params['url'] = None return params - eng_region = traits.get_region(params['searxng_locale'], traits.all_locale) eng_lang = get_ddg_lang(traits, params['searxng_locale']) args = { @@ -86,6 +86,12 @@ def request(query, params): params['url'] = f'https://duckduckgo.com/{search_path_map[ddg_category]}.js?{urlencode(args)}' + # sending these two headers prevents rate limiting for the query + params['headers'] = { + 'Referer': 'https://duckduckgo.com/', + 'X-Requested-With': 'XMLHttpRequest', + } + return params |