feat: add support for SearXNG HTTP basic authentication
This commit is contained in:
@@ -26,7 +26,7 @@ from duckduckgo_search.exceptions import ( # type: ignore[import-untyped]
|
||||
RatelimitException,
|
||||
)
|
||||
|
||||
from gitea.config import SEARXNG_URL
|
||||
from gitea.config import SEARXNG_URL, SEARXNG_USERNAME, SEARXNG_PASSWORD
|
||||
|
||||
logger: logging.Logger = logging.getLogger("research-tools")
|
||||
|
||||
@@ -38,6 +38,9 @@ _USER_AGENT: str = (
|
||||
)
|
||||
# SearXNG instance
|
||||
_SEARXNG_URL: str = SEARXNG_URL
|
||||
_SEARXNG_USERNAME: str = SEARXNG_USERNAME
|
||||
_SEARXNG_PASSWORD: str = SEARXNG_PASSWORD
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -196,9 +199,13 @@ class ResearchTools:
|
||||
if time_range:
|
||||
params["time_range"] = time_range
|
||||
|
||||
auth = None
|
||||
if _SEARXNG_USERNAME and _SEARXNG_PASSWORD:
|
||||
auth = (_SEARXNG_USERNAME, _SEARXNG_PASSWORD)
|
||||
|
||||
try:
|
||||
with httpx.Client(
|
||||
timeout=_DEFAULT_TIMEOUT, follow_redirects=True
|
||||
timeout=_DEFAULT_TIMEOUT, follow_redirects=True, auth=auth
|
||||
) as client:
|
||||
response = client.get(
|
||||
f"{_SEARXNG_URL}/search",
|
||||
|
||||
Reference in New Issue
Block a user