summaryrefslogtreecommitdiff
path: root/searx/metrology
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-03-18 19:59:01 +0100
committerAlexandre Flament <alex@al-f.net>2021-04-10 15:38:33 +0200
commiteaa694fb7d0e47b943bc6d6edb6cb6a40ab2d85e (patch)
tree024786c8a7003be24bbc566cb8c8e734a143f99d /searx/metrology
parent111180705b6f3b142732eb6325de1346f6372828 (diff)
[enh] replace requests by httpx
Diffstat (limited to 'searx/metrology')
-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)