2"""Raise exception for an HTTP response is an error.
7 SearxEngineCaptchaException,
8 SearxEngineTooManyRequestsException,
9 SearxEngineAccessDeniedException,
11from searx
import get_setting
15 if resp.status_code
in [429, 503]:
16 if (
'__cf_chl_jschl_tk__=' in resp.text)
or (
17 '/cdn-cgi/challenge-platform/' in resp.text
18 and 'orchestrate/jsch/v1' in resp.text
19 and 'window._cf_chl_enter(' in resp.text
22 if resp.status_code == 403
and '__cf_chl_captcha_tk__=' in resp.text:
28 return resp.status_code == 403
and '<span class="cf-error-code">1020</span>' in resp.text
32 if resp.headers.get(
'Server',
'').startswith(
'cloudflare'):
37 message=
'Cloudflare CAPTCHA', suspended_time=get_setting(
'search.suspended_times.cf_SearxEngineCaptcha')
42 message=
'Cloudflare Firewall',
43 suspended_time=get_setting(
'search.suspended_times.cf_SearxEngineAccessDenied'),
48 if resp.status_code == 503
and '"https://www.google.com/recaptcha/' in resp.text:
50 message=
'ReCAPTCHA', suspended_time=get_setting(
'search.suspended_times.recaptcha_SearxEngineCaptcha')
59def raise_for_httperror(resp):
60 """Raise exception for an HTTP response is an error.
63 resp (requests.Response): Response to check
66 requests.HTTPError: raise by resp.raise_for_status()
67 searx.exceptions.SearxEngineAccessDeniedException: raise when the HTTP status code is 402 or 403.
68 searx.exceptions.SearxEngineTooManyRequestsException: raise when the HTTP status code is 429.
69 searx.exceptions.SearxEngineCaptchaException: raise when if CATPCHA challenge is detected.
71 if resp.status_code
and resp.status_code >= 400:
73 if resp.status_code
in (402, 403):
75 if resp.status_code == 429:
77 resp.raise_for_status()
is_cloudflare_firewall(resp)
is_cloudflare_challenge(resp)
raise_for_recaptcha(resp)
raise_for_cloudflare_captcha(resp)