From cfca838549c8512cd8f06c99887e883c4b84c6d9 Mon Sep 17 00:00:00 2001 From: imoes Date: Thu, 16 Apr 2026 20:07:37 +0200 Subject: [PATCH] fix: robustly detect HTTP proxy for DuckDuckGo search across ddgs versions The previous proxy detection only read lowercase https_proxy/http_proxy env vars and passed them to DDGS(proxy=...). This broke silently when the ddgs package was updated (open-webui:main image repulled): newer versions use a different internal httpx client configuration that requires uppercase env vars (HTTPS_PROXY/HTTP_PROXY) to reliably pick up proxy settings. Changes: - Read proxy from all four env var variants (https_proxy, HTTPS_PROXY, http_proxy, HTTP_PROXY) with lowercase taking priority. - Use os.environ.setdefault() to ensure uppercase HTTPS_PROXY/HTTP_PROXY are set before DDGS is instantiated, so httpx picks up the proxy automatically regardless of which ddgs version is installed. Co-Authored-By: Claude Sonnet 4.6 --- backend/open_webui/retrieval/web/duckduckgo.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/retrieval/web/duckduckgo.py b/backend/open_webui/retrieval/web/duckduckgo.py index ea3b09022f..fddd12a195 100644 --- a/backend/open_webui/retrieval/web/duckduckgo.py +++ b/backend/open_webui/retrieval/web/duckduckgo.py @@ -26,7 +26,18 @@ def search_duckduckgo( Returns: list[SearchResult]: A list of search results """ - proxy = os.environ.get("https_proxy") or os.environ.get("http_proxy") + proxy = ( + os.environ.get("https_proxy") + or os.environ.get("HTTPS_PROXY") + or os.environ.get("http_proxy") + or os.environ.get("HTTP_PROXY") + ) + # httpx (used internally by ddgs) reliably reads uppercase env vars; + # ensure they are set so the proxy is picked up regardless of ddgs version + if proxy: + os.environ.setdefault("HTTPS_PROXY", proxy) + os.environ.setdefault("HTTP_PROXY", proxy) + # Use the DDGS context manager to create a DDGS object search_results = [] with DDGS(proxy=proxy) as ddgs: