2"""Raise exception for an HTTP response is an error.
8 SearxEngineCaptchaException,
9 SearxEngineTooManyRequestsException,
10 SearxEngineAccessDeniedException,
12from searx
import get_setting
19 if resp.status_code
in [429, 503]:
20 if (
'__cf_chl_jschl_tk__=' in resp.text)
or (
21 '/cdn-cgi/challenge-platform/' in resp.text
22 and 'orchestrate/jsch/v1' in resp.text
23 and 'window._cf_chl_enter(' in resp.text
26 if resp.status_code == 403
and '__cf_chl_captcha_tk__=' in resp.text:
32 return resp.status_code == 403
and '<span class="cf-error-code">1020</span>' in resp.text
36 if resp.headers.get(
'Server',
'').startswith(
'cloudflare'):
41 message=
'Cloudflare CAPTCHA', suspended_time=
get_setting(
'search.suspended_times.cf_SearxEngineCaptcha')
46 message=
'Cloudflare Firewall',
47 suspended_time=
get_setting(
'search.suspended_times.cf_SearxEngineAccessDenied'),
52 if resp.status_code == 503
and '"https://www.google.com/recaptcha/' in resp.text:
54 message=
'ReCAPTCHA', suspended_time=
get_setting(
'search.suspended_times.recaptcha_SearxEngineCaptcha')
63def raise_for_httperror(resp:
"SXNG_Response") ->
None:
64 """Raise exception for an HTTP response is an error.
67 resp (requests.Response): Response to check
70 requests.HTTPError: raise by resp.raise_for_status()
71 searx.exceptions.SearxEngineAccessDeniedException: raise when the HTTP status code is 402 or 403.
72 searx.exceptions.SearxEngineTooManyRequestsException: raise when the HTTP status code is 429.
73 searx.exceptions.SearxEngineCaptchaException: raise when if CATPCHA challenge is detected.
75 if resp.status_code
and resp.status_code >= 400:
77 if resp.status_code
in (402, 403):
79 if resp.status_code == 429:
81 resp.raise_for_status()
is_cloudflare_firewall("SXNG_Response" resp)
raise_for_captcha("SXNG_Response" resp)
raise_for_cloudflare_captcha("SXNG_Response" resp)
raise_for_recaptcha("SXNG_Response" resp)
is_cloudflare_challenge("SXNG_Response" resp)
t.Any get_setting(str name, t.Any default=_unset)