.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.network.raise_for_httperror Namespace Reference

Functions

 is_cloudflare_challenge ("SXNG_Response" resp)
 is_cloudflare_firewall ("SXNG_Response" resp)
 raise_for_cloudflare_captcha ("SXNG_Response" resp)
 raise_for_recaptcha ("SXNG_Response" resp)
 raise_for_captcha ("SXNG_Response" resp)
None raise_for_httperror ("SXNG_Response" resp)

Detailed Description

Raise exception for an HTTP response is an error.

Function Documentation

◆ is_cloudflare_challenge()

searx.network.raise_for_httperror.is_cloudflare_challenge ( "SXNG_Response" resp)

Definition at line 18 of file raise_for_httperror.py.

18def is_cloudflare_challenge(resp: "SXNG_Response"):
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
24 ):
25 return True
26 if resp.status_code == 403 and '__cf_chl_captcha_tk__=' in resp.text:
27 return True
28 return False
29
30

Referenced by raise_for_cloudflare_captcha().

Here is the caller graph for this function:

◆ is_cloudflare_firewall()

searx.network.raise_for_httperror.is_cloudflare_firewall ( "SXNG_Response" resp)

Definition at line 31 of file raise_for_httperror.py.

31def is_cloudflare_firewall(resp: "SXNG_Response"):
32 return resp.status_code == 403 and '<span class="cf-error-code">1020</span>' in resp.text
33
34

Referenced by raise_for_cloudflare_captcha().

Here is the caller graph for this function:

◆ raise_for_captcha()

searx.network.raise_for_httperror.raise_for_captcha ( "SXNG_Response" resp)

Definition at line 58 of file raise_for_httperror.py.

58def raise_for_captcha(resp: "SXNG_Response"):
59 raise_for_cloudflare_captcha(resp)
60 raise_for_recaptcha(resp)
61
62

References raise_for_cloudflare_captcha(), and raise_for_recaptcha().

Referenced by raise_for_httperror().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ raise_for_cloudflare_captcha()

searx.network.raise_for_httperror.raise_for_cloudflare_captcha ( "SXNG_Response" resp)

Definition at line 35 of file raise_for_httperror.py.

35def raise_for_cloudflare_captcha(resp: "SXNG_Response"):
36 if resp.headers.get('Server', '').startswith('cloudflare'):
37 if is_cloudflare_challenge(resp):
38 # https://support.cloudflare.com/hc/en-us/articles/200170136-Understanding-Cloudflare-Challenge-Passage-Captcha-
39 # suspend for 2 weeks
40 raise SearxEngineCaptchaException(
41 message='Cloudflare CAPTCHA', suspended_time=get_setting('search.suspended_times.cf_SearxEngineCaptcha')
42 )
43
44 if is_cloudflare_firewall(resp):
45 raise SearxEngineAccessDeniedException(
46 message='Cloudflare Firewall',
47 suspended_time=get_setting('search.suspended_times.cf_SearxEngineAccessDenied'),
48 )
49
50

References searx.get_setting(), is_cloudflare_challenge(), and is_cloudflare_firewall().

Referenced by raise_for_captcha().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ raise_for_httperror()

None searx.network.raise_for_httperror.raise_for_httperror ( "SXNG_Response" resp)
Raise exception for an HTTP response is an error.

Args:
    resp (requests.Response): Response to check

Raises:
    requests.HTTPError: raise by resp.raise_for_status()
    searx.exceptions.SearxEngineAccessDeniedException: raise when the HTTP status code is 402 or 403.
    searx.exceptions.SearxEngineTooManyRequestsException: raise when the HTTP status code is 429.
    searx.exceptions.SearxEngineCaptchaException: raise when if CATPCHA challenge is detected.

Definition at line 63 of file raise_for_httperror.py.

63def raise_for_httperror(resp: "SXNG_Response") -> None:
64 """Raise exception for an HTTP response is an error.
65
66 Args:
67 resp (requests.Response): Response to check
68
69 Raises:
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.
74 """
75 if resp.status_code and resp.status_code >= 400:
76 raise_for_captcha(resp)
77 if resp.status_code in (402, 403):
78 raise SearxEngineAccessDeniedException(message='HTTP error ' + str(resp.status_code))
79 if resp.status_code == 429:
80 raise SearxEngineTooManyRequestsException()
81 resp.raise_for_status()

References raise_for_captcha().

Here is the call graph for this function:

◆ raise_for_recaptcha()

searx.network.raise_for_httperror.raise_for_recaptcha ( "SXNG_Response" resp)

Definition at line 51 of file raise_for_httperror.py.

51def raise_for_recaptcha(resp: "SXNG_Response"):
52 if resp.status_code == 503 and '"https://www.google.com/recaptcha/' in resp.text:
53 raise SearxEngineCaptchaException(
54 message='ReCAPTCHA', suspended_time=get_setting('search.suspended_times.recaptcha_SearxEngineCaptcha')
55 )
56
57

References searx.get_setting().

Referenced by raise_for_captcha().

Here is the call graph for this function:
Here is the caller graph for this function: