From d24e489850aa9531430122b7e8c816922ead914c Mon Sep 17 00:00:00 2001 From: Bnyro Date: Thu, 10 Jul 2025 15:16:21 +0200 Subject: [PATCH] [chore] engines: remove redundant usages of utils#gen_useragent These engines override the user agent manually using `gen_useragent`, although that's already done in the online preprocessor that runs before the actual `request(query, params)` method is called. Hence, this call is duplicated. Related: - https://github.com/searxng/searxng/pull/4990#discussion_r2195142838 --- searx/engines/quark.py | 5 +---- searx/engines/semantic_scholar.py | 15 ++++++++------- searx/engines/uxwing.py | 3 +-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/searx/engines/quark.py b/searx/engines/quark.py index 1c2e84492..38d431da9 100644 --- a/searx/engines/quark.py +++ b/searx/engines/quark.py @@ -6,7 +6,7 @@ from datetime import datetime import re import json -from searx.utils import html_to_text, gen_useragent +from searx.utils import html_to_text from searx.exceptions import SearxEngineAPIException, SearxEngineCaptchaException # Metadata @@ -77,9 +77,6 @@ def request(query, params): query_params["tl_request"] = time_range_dict.get(params['time_range']) params["url"] = f"{query_url}?{urlencode(query_params)}" - params["headers"] = { - "User-Agent": gen_useragent(), - } return params diff --git a/searx/engines/semantic_scholar.py b/searx/engines/semantic_scholar.py index 450f3f765..f5a692792 100644 --- a/searx/engines/semantic_scholar.py +++ b/searx/engines/semantic_scholar.py @@ -7,7 +7,7 @@ from lxml import html from flask_babel import gettext from searx.network import get -from searx.utils import eval_xpath_getindex, gen_useragent, html_to_text +from searx.utils import eval_xpath_getindex, html_to_text about = { @@ -41,12 +41,13 @@ def _get_ui_version(): def request(query, params): params['url'] = search_url params['method'] = 'POST' - params['headers'] = { - 'Content-Type': 'application/json', - 'X-S2-UI-Version': _get_ui_version(), - 'X-S2-Client': "webapp-browser", - 'User-Agent': gen_useragent(), - } + params['headers'].update( + { + 'Content-Type': 'application/json', + 'X-S2-UI-Version': _get_ui_version(), + 'X-S2-Client': "webapp-browser", + } + ) params['data'] = dumps( { "queryString": query, diff --git a/searx/engines/uxwing.py b/searx/engines/uxwing.py index aef8b8fee..59bb75afc 100644 --- a/searx/engines/uxwing.py +++ b/searx/engines/uxwing.py @@ -4,7 +4,7 @@ from urllib.parse import quote_plus from lxml import html -from searx.utils import eval_xpath, eval_xpath_list, extract_text, gen_useragent +from searx.utils import eval_xpath, eval_xpath_list, extract_text about = { "website": 'https://uxwing.com', @@ -22,7 +22,6 @@ enable_http2 = False def request(query, params): params['url'] = f"{base_url}/?s={quote_plus(query)}" - params['headers'] = {'User-Agent': gen_useragent()} return params