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

Functions

 is_cloudflare_challenge (resp)
 
 is_cloudflare_firewall (resp)
 
 raise_for_cloudflare_captcha (resp)
 
 raise_for_recaptcha (resp)
 
 raise_for_captcha (resp)
 
 raise_for_httperror (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 ( resp)

Definition at line 14 of file raise_for_httperror.py.

14def is_cloudflare_challenge(resp):
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
20 ):
21 return True
22 if resp.status_code == 403 and '__cf_chl_captcha_tk__=' in resp.text:
23 return True
24 return False
25
26

Referenced by searx.network.raise_for_httperror.raise_for_cloudflare_captcha().

+ Here is the caller graph for this function:

◆ is_cloudflare_firewall()

searx.network.raise_for_httperror.is_cloudflare_firewall ( resp)

Definition at line 27 of file raise_for_httperror.py.

27def is_cloudflare_firewall(resp):
28 return resp.status_code == 403 and '<span class="cf-error-code">1020</span>' in resp.text
29
30

Referenced by searx.network.raise_for_httperror.raise_for_cloudflare_captcha().

+ Here is the caller graph for this function:

◆ raise_for_captcha()

searx.network.raise_for_httperror.raise_for_captcha ( resp)

Definition at line 54 of file raise_for_httperror.py.

54def raise_for_captcha(resp):
55 raise_for_cloudflare_captcha(resp)
56 raise_for_recaptcha(resp)
57
58

References searx.network.raise_for_httperror.raise_for_cloudflare_captcha(), and searx.network.raise_for_httperror.raise_for_recaptcha().

Referenced by searx.network.raise_for_httperror.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 ( resp)

Definition at line 31 of file raise_for_httperror.py.

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

References searx.network.raise_for_httperror.is_cloudflare_challenge(), and searx.network.raise_for_httperror.is_cloudflare_firewall().

Referenced by searx.network.raise_for_httperror.raise_for_captcha().

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

◆ raise_for_httperror()

searx.network.raise_for_httperror.raise_for_httperror ( 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 59 of file raise_for_httperror.py.

59def raise_for_httperror(resp):
60 """Raise exception for an HTTP response is an error.
61
62 Args:
63 resp (requests.Response): Response to check
64
65 Raises:
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.
70 """
71 if resp.status_code and resp.status_code >= 400:
72 raise_for_captcha(resp)
73 if resp.status_code in (402, 403):
74 raise SearxEngineAccessDeniedException(message='HTTP error ' + str(resp.status_code))
75 if resp.status_code == 429:
76 raise SearxEngineTooManyRequestsException()
77 resp.raise_for_status()

References searx.network.raise_for_httperror.raise_for_captcha().

+ Here is the call graph for this function:

◆ raise_for_recaptcha()

searx.network.raise_for_httperror.raise_for_recaptcha ( resp)

Definition at line 47 of file raise_for_httperror.py.

47def raise_for_recaptcha(resp):
48 if resp.status_code == 503 and '"https://www.google.com/recaptcha/' in resp.text:
49 raise SearxEngineCaptchaException(
50 message='ReCAPTCHA', suspended_time=get_setting('search.suspended_times.recaptcha_SearxEngineCaptcha')
51 )
52
53

Referenced by searx.network.raise_for_httperror.raise_for_captcha().

+ Here is the caller graph for this function: