on master help sign in
[fix] duckduckgo engine: "!ddg !g" do not redirect to google

* searx understand "!ddg !g time" as : send "!g time" to DDG * !g a DDG bang for Google: DDG return a HTTP redirect to Google This commit adds a the allows_redirect param not to follow HTTP redirect. The DDG engine returns a empty result as before without HTTP redirect.

commitc22d4c764cae6097c463045e86bc81b4becb2545 authorAlexandre Flament <alex@al-f.net> dateTue 9 Feb 2021, 12:07 (6 years ago) parentd766604
3 files changed+12−1
docs/dev/engine_overview.rst+1 searx/engines/duckduckgo.py+7−1 searx/search/processors/online.py+4
docs/dev/engine_overview.rst+1
@@ -169,6 +169,7 @@ headers set HTTP header information
169169data set HTTP data information
170170cookies set HTTP cookies
171171verify bool Performing SSL-Validity check
172+allow_redirects bool Follow redirects
172173max_redirects int maximum redirects, hard limit
173174soft_max_redirects int maximum redirects, soft limit. Record an error but don't stop the engine
174175raise_for_httperror bool True by default: raise an exception if the HTTP code of response is >= 300
searx/engines/duckduckgo.py+7−1
@@ -75,12 +75,18 @@ def request(query, params):
7575 params['data']['kl'] = region_code
7676 params['cookies']['kl'] = region_code
7777
78− params['data']['df'] = time_range_dict.get(params['time_range'], '')
78+ if params['time_range'] in time_range_dict:
79+ params['data']['df'] = time_range_dict[params['time_range']]
80+
81+ params['allow_redirects'] = False
7982 return params
8083
8184
8285# get response from search-request
8386def response(resp):
87+ if resp.status_code == 303:
88+ return []
89+
8490 # ping
8591 headers_ping = dict_subset(resp.request.headers, ['User-Agent', 'Accept-Encoding', 'Accept', 'Cookie'])
8692 get(url_ping, headers=headers_ping)
searx/search/processors/online.py+4
@@ -73,6 +73,10 @@ class OnlineProcessor(EngineProcessor):
7373 if max_redirects:
7474 request_args['max_redirects'] = max_redirects
7575
76+ # allow_redirects
77+ if 'allow_redirects' in params:
78+ request_args['allow_redirects'] = params['allow_redirects']
79+
7680 # soft_max_redirects
7781 soft_max_redirects = params.get('soft_max_redirects', max_redirects or 0)
7882