summaryrefslogtreecommitdiff
path: root/searx/network
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2021-05-24 17:32:03 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2021-05-24 17:40:10 +0200
commite4211da63976de3a61345ec4c333cdc1edc0868d (patch)
treef56eee4634400b6924676571f10017a4d4d2b191 /searx/network
parent44efa911ba24ca6089e61922e45f096b351d3871 (diff)
downloadsearxng-e4211da63976de3a61345ec4c333cdc1edc0868d.tar.gz
searxng-e4211da63976de3a61345ec4c333cdc1edc0868d.zip
[pylint] searx/network/raise_for_httperror.py
No functional change! - fix messages from pylint - add ``global NETWORKS`` - normalized indentations Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/network')
-rw-r--r--searx/network/raise_for_httperror.py42
1 files changed, 28 insertions, 14 deletions
diff --git a/searx/network/raise_for_httperror.py b/searx/network/raise_for_httperror.py
index bd12df9a9..0f550918d 100644
--- a/searx/network/raise_for_httperror.py
+++ b/searx/network/raise_for_httperror.py
@@ -1,17 +1,23 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+# pylint: disable=missing-function-docstring
+"""Raise exception for an HTTP response is an error.
+
"""
-Raise exception for an HTTP response is an error.
-"""
-from searx.exceptions import (SearxEngineCaptchaException, SearxEngineTooManyRequestsException,
- SearxEngineAccessDeniedException)
+from searx.exceptions import (
+ SearxEngineCaptchaException,
+ SearxEngineTooManyRequestsException,
+ SearxEngineAccessDeniedException,
+)
def is_cloudflare_challenge(resp):
if resp.status_code in [429, 503]:
- if ('__cf_chl_jschl_tk__=' in resp.text)\
- or ('/cdn-cgi/challenge-platform/' in resp.text
- and 'orchestrate/jsch/v1' in resp.text
- and 'window._cf_chl_enter(' in resp.text):
+ if (('__cf_chl_jschl_tk__=' in resp.text)
+ or ('/cdn-cgi/challenge-platform/' in resp.text
+ and 'orchestrate/jsch/v1' in resp.text
+ and 'window._cf_chl_enter(' in resp.text
+ )):
return True
if resp.status_code == 403 and '__cf_chl_captcha_tk__=' in resp.text:
return True
@@ -27,15 +33,21 @@ def raise_for_cloudflare_captcha(resp):
if is_cloudflare_challenge(resp):
# https://support.cloudflare.com/hc/en-us/articles/200170136-Understanding-Cloudflare-Challenge-Passage-Captcha-
# suspend for 2 weeks
- raise SearxEngineCaptchaException(message='Cloudflare CAPTCHA', suspended_time=3600 * 24 * 15)
+ raise SearxEngineCaptchaException(
+ message='Cloudflare CAPTCHA',
+ suspended_time=3600 * 24 * 15
+ )
if is_cloudflare_firewall(resp):
- raise SearxEngineAccessDeniedException(message='Cloudflare Firewall', suspended_time=3600 * 24)
+ raise SearxEngineAccessDeniedException(
+ message='Cloudflare Firewall', suspended_time=3600 * 24
+ )
def raise_for_recaptcha(resp):
- if resp.status_code == 503 \
- and '"https://www.google.com/recaptcha/' in resp.text:
+ if (resp.status_code == 503
+ and '"https://www.google.com/recaptcha/' in resp.text
+ ):
raise SearxEngineCaptchaException(message='ReCAPTCHA', suspended_time=3600 * 24 * 7)
@@ -59,8 +71,10 @@ def raise_for_httperror(resp):
if resp.status_code and resp.status_code >= 400:
raise_for_captcha(resp)
if resp.status_code in (402, 403):
- raise SearxEngineAccessDeniedException(message='HTTP error ' + str(resp.status_code),
- suspended_time=3600 * 24)
+ raise SearxEngineAccessDeniedException(
+ message='HTTP error ' + str(resp.status_code),
+ suspended_time=3600 * 24
+ )
if resp.status_code == 429:
raise SearxEngineTooManyRequestsException()
resp.raise_for_status()