summaryrefslogtreecommitdiff
path: root/searx/metrology/error_recorder.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-04-12 17:34:21 +0200
committerGitHub <noreply@github.com>2021-04-12 17:34:21 +0200
commit01cefffbf6efa8a027e0e7d720970fffadb6337a (patch)
treea4c37f7b73897c7635ee5fab01c1e8e967e23d8a /searx/metrology/error_recorder.py
parent6c0114567e7ba1b3f4a54327eddf658b7474ca58 (diff)
parentd14994dc73ba5c95382812581dac146d9eceaafa (diff)
Merge pull request #1 from metasearch-lab/httpx_networks
Httpx networks
Diffstat (limited to 'searx/metrology/error_recorder.py')
-rw-r--r--searx/metrology/error_recorder.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/searx/metrology/error_recorder.py b/searx/metrology/error_recorder.py
index f533e4e8b..167d1c8aa 100644
--- a/searx/metrology/error_recorder.py
+++ b/searx/metrology/error_recorder.py
@@ -3,7 +3,7 @@ import inspect
import logging
from json import JSONDecodeError
from urllib.parse import urlparse
-from requests.exceptions import RequestException
+from httpx import HTTPError, HTTPStatusError
from searx.exceptions import (SearxXPathSyntaxException, SearxEngineXPathException, SearxEngineAPIException,
SearxEngineAccessDeniedException)
from searx import logger
@@ -60,28 +60,28 @@ def get_trace(traces):
return traces[-1]
-def get_hostname(exc: RequestException) -> typing.Optional[None]:
+def get_hostname(exc: HTTPError) -> typing.Optional[None]:
url = exc.request.url
if url is None and exc.response is not None:
url = exc.response.url
return urlparse(url).netloc
-def get_request_exception_messages(exc: RequestException)\
+def get_request_exception_messages(exc: HTTPError)\
-> typing.Tuple[typing.Optional[str], typing.Optional[str], typing.Optional[str]]:
url = None
status_code = None
reason = None
hostname = None
- if exc.request is not None:
+ if hasattr(exc, 'request') and exc.request is not None:
url = exc.request.url
- if url is None and exc.response is not None:
+ if url is None and hasattr(exc, 'response') and exc.respones is not None:
url = exc.response.url
if url is not None:
- hostname = str(urlparse(url).netloc)
- if exc.response is not None:
+ hostname = url.host
+ if isinstance(exc, HTTPStatusError):
status_code = str(exc.response.status_code)
- reason = exc.response.reason
+ reason = exc.response.reason_phrase
return (status_code, reason, hostname)
@@ -92,7 +92,7 @@ def get_messages(exc, filename) -> typing.Tuple:
return (str(exc), )
if isinstance(exc, ValueError) and 'lxml' in filename:
return (str(exc), )
- if isinstance(exc, RequestException):
+ if isinstance(exc, HTTPError):
return get_request_exception_messages(exc)
if isinstance(exc, SearxXPathSyntaxException):
return (exc.xpath_str, exc.message)