From 7d0a78a43a664dfc16a039424ce4a05960ec4655 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 28 Apr 2025 16:47:34 +0400 Subject: [PATCH] refac: aiohttp trust_env=True --- backend/open_webui/routers/ollama.py | 3 ++- backend/open_webui/routers/openai.py | 6 ++++-- backend/open_webui/routers/pipelines.py | 4 ++-- backend/open_webui/utils/code_interpreter.py | 2 +- backend/open_webui/utils/oauth.py | 4 ++-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/backend/open_webui/routers/ollama.py b/backend/open_webui/routers/ollama.py index 115bab938..b41a240a7 100644 --- a/backend/open_webui/routers/ollama.py +++ b/backend/open_webui/routers/ollama.py @@ -219,7 +219,8 @@ async def verify_connection( key = form_data.key async with aiohttp.ClientSession( - timeout=aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST) + trust_env=True, + timeout=aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST), ) as session: try: async with session.get( diff --git a/backend/open_webui/routers/openai.py b/backend/open_webui/routers/openai.py index 587739ead..02a81209c 100644 --- a/backend/open_webui/routers/openai.py +++ b/backend/open_webui/routers/openai.py @@ -463,7 +463,8 @@ async def get_models( r = None async with aiohttp.ClientSession( - timeout=aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST) + trust_env=True, + timeout=aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST), ) as session: try: async with session.get( @@ -544,7 +545,8 @@ async def verify_connection( key = form_data.key async with aiohttp.ClientSession( - timeout=aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST) + trust_env=True, + timeout=aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST), ) as session: try: async with session.get( diff --git a/backend/open_webui/routers/pipelines.py b/backend/open_webui/routers/pipelines.py index 10c8e9b2e..f14002502 100644 --- a/backend/open_webui/routers/pipelines.py +++ b/backend/open_webui/routers/pipelines.py @@ -66,7 +66,7 @@ async def process_pipeline_inlet_filter(request, payload, user, models): if "pipeline" in model: sorted_filters.append(model) - async with aiohttp.ClientSession() as session: + async with aiohttp.ClientSession(trust_env=True) as session: for filter in sorted_filters: urlIdx = filter.get("urlIdx") if urlIdx is None: @@ -115,7 +115,7 @@ async def process_pipeline_outlet_filter(request, payload, user, models): if "pipeline" in model: sorted_filters = [model] + sorted_filters - async with aiohttp.ClientSession() as session: + async with aiohttp.ClientSession(trust_env=True) as session: for filter in sorted_filters: urlIdx = filter.get("urlIdx") if urlIdx is None: diff --git a/backend/open_webui/utils/code_interpreter.py b/backend/open_webui/utils/code_interpreter.py index 312baff24..1ad5ee93c 100644 --- a/backend/open_webui/utils/code_interpreter.py +++ b/backend/open_webui/utils/code_interpreter.py @@ -50,7 +50,7 @@ class JupyterCodeExecuter: self.password = password self.timeout = timeout self.kernel_id = "" - self.session = aiohttp.ClientSession(base_url=self.base_url) + self.session = aiohttp.ClientSession(trust_env=True, base_url=self.base_url) self.params = {} self.result = ResultModel() diff --git a/backend/open_webui/utils/oauth.py b/backend/open_webui/utils/oauth.py index 36994da5f..d526382c1 100644 --- a/backend/open_webui/utils/oauth.py +++ b/backend/open_webui/utils/oauth.py @@ -304,7 +304,7 @@ class OAuthManager: try: access_token = token.get("access_token") headers = {"Authorization": f"Bearer {access_token}"} - async with aiohttp.ClientSession() as session: + async with aiohttp.ClientSession(trust_env=True) as session: async with session.get( "https://api.github.com/user/emails", headers=headers ) as resp: @@ -386,7 +386,7 @@ class OAuthManager: get_kwargs["headers"] = { "Authorization": f"Bearer {access_token}", } - async with aiohttp.ClientSession() as session: + async with aiohttp.ClientSession(trust_env=True) as session: async with session.get( picture_url, **get_kwargs ) as resp: