132 def get_params(self, search_query:
"SearchQuery", engine_category: str) -> OnlineParams |
None:
133 """Returns a dictionary with the :ref:`request params <engine request
134 online>` (:py:obj:`OnlineParams`), if the search condition is not
135 supported by the engine, ``None`` is returned."""
137 base_params: RequestParams |
None = super().
get_params(search_query, engine_category)
138 if base_params
is None:
143 headers = params[
"headers"]
146 headers[
"User-Agent"] = gen_useragent()
149 if self.
engine.send_accept_language_header
and search_query.locale:
150 ac_lang = search_query.locale.language
151 if search_query.locale.territory:
152 ac_lang =
"%s-%s,%s;q=0.9,*;q=0.5" % (
153 search_query.locale.language,
154 search_query.locale.territory,
155 search_query.locale.language,
157 headers[
"Accept-Language"] = ac_lang
159 self.
logger.debug(
"HTTP Accept-Language: %s", headers.get(
"Accept-Language",
""))
165 request_args: dict[str, t.Any] = {
166 "headers": params[
"headers"],
167 "cookies": params[
"cookies"],
168 "auth": params[
"auth"],
171 verify = params.get(
"verify")
172 if verify
is not None:
173 request_args[
"verify"] = verify
176 max_redirects = params.get(
"max_redirects")
178 request_args[
"max_redirects"] = max_redirects
181 if "allow_redirects" in params:
182 request_args[
"allow_redirects"] = params[
"allow_redirects"]
185 soft_max_redirects: int = params.get(
"soft_max_redirects", max_redirects
or 0)
188 request_args[
"raise_for_httperror"] = params.get(
"raise_for_httperror",
True)
191 if params[
"method"] ==
"GET":
192 req = searx.network.get
194 req = searx.network.post
196 request_args[
"data"] = params[
"data"]
198 request_args[
"json"] = params[
"json"]
199 if params[
"content"]:
200 request_args[
"content"] = params[
"content"]
203 response = req(params[
"url"], **request_args)
206 if len(response.history) > soft_max_redirects:
209 status_code = str(response.status_code
or "")
210 reason = response.reason_phrase
or ""
211 hostname = response.url.host
214 "{} redirects, maximum: {}".format(len(response.history), soft_max_redirects),
215 (status_code, reason, hostname),
240 params: OnlineParams,
241 result_container:
"ResultContainer",
243 timeout_limit: float,
251 except ssl.SSLError
as e:
254 self.
logger.error(
"SSLError {}, verify={}".format(e, searx.network.get_network(self.
engine.name).verify))
255 except (httpx.TimeoutException, asyncio.TimeoutError)
as e:
259 "HTTP requests timeout (search duration : {0} s, timeout: {1} s) : {2}".format(
260 default_timer() - start_time, timeout_limit, e.__class__.__name__
263 except (httpx.HTTPError, httpx.StreamError)
as e:
267 "requests exception (search duration : {0} s, timeout: {1} s) : {2}".format(
268 default_timer() - start_time, timeout_limit, e
272 SearxEngineCaptchaException,
273 SearxEngineTooManyRequestsException,
274 SearxEngineAccessDeniedException,
277 self.
logger.exception(e.message)
278 except Exception
as e:
280 self.
logger.exception(
"exception : {0}".format(e))