From 9fed938de182d7d603aef3255be105f03cb490f4 Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:36:44 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20Fix:=20httpx=20proxy=20=E4=B8=8E=20aioh?= =?UTF-8?q?ttp=20timeout=20=E5=8F=82=E6=95=B0=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20(#3152)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- envs/pydantic-v1/poetry.lock | 12 ++++++------ envs/pydantic-v2/poetry.lock | 12 ++++++------ nonebot/drivers/aiohttp.py | 8 ++++---- nonebot/drivers/httpx.py | 4 +++- poetry.lock | 2 +- pyproject.toml | 6 +++--- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/envs/pydantic-v1/poetry.lock b/envs/pydantic-v1/poetry.lock index f3e8307d..5ff2d288 100644 --- a/envs/pydantic-v1/poetry.lock +++ b/envs/pydantic-v1/poetry.lock @@ -1388,13 +1388,13 @@ files = [] develop = true [package.dependencies] -aiohttp = {version = "^3.9.0b0", extras = ["speedups"], optional = true} +aiohttp = {version = "^3.11.0", extras = ["speedups"], optional = true} anyio = "^4.4.0" exceptiongroup = "^1.2.2" fastapi = {version = ">=0.93.0,<1.0.0", optional = true} -httpx = {version = ">=0.20.0,<1.0.0", extras = ["http2"], optional = true} +httpx = {version = ">=0.26.0,<1.0.0", extras = ["http2"], optional = true} loguru = ">=0.6.0,<1.0.0" -pydantic = ">=1.10.0,<3.0.0,!=2.5.0,!=2.5.1,!=2.10.0" +pydantic = ">=1.10.0,<3.0.0,!=2.5.0,!=2.5.1,!=2.10.0,!=2.10.1" pygtrie = "^2.4.1" python-dotenv = ">=0.21.0,<2.0.0" Quart = {version = ">=0.18.0,<1.0.0", optional = true} @@ -1405,10 +1405,10 @@ websockets = {version = ">=10.0", optional = true} yarl = "^1.7.2" [package.extras] -aiohttp = ["aiohttp[speedups] (>=3.9.0b0,<4.0.0)"] -all = ["Quart (>=0.18.0,<1.0.0)", "aiohttp[speedups] (>=3.9.0b0,<4.0.0)", "fastapi (>=0.93.0,<1.0.0)", "httpx[http2] (>=0.20.0,<1.0.0)", "uvicorn[standard] (>=0.20.0,<1.0.0)", "websockets (>=10.0)"] +aiohttp = ["aiohttp[speedups] (>=3.11.0,<4.0.0)"] +all = ["Quart (>=0.18.0,<1.0.0)", "aiohttp[speedups] (>=3.11.0,<4.0.0)", "fastapi (>=0.93.0,<1.0.0)", "httpx[http2] (>=0.26.0,<1.0.0)", "uvicorn[standard] (>=0.20.0,<1.0.0)", "websockets (>=10.0)"] fastapi = ["fastapi (>=0.93.0,<1.0.0)", "uvicorn[standard] (>=0.20.0,<1.0.0)"] -httpx = ["httpx[http2] (>=0.20.0,<1.0.0)"] +httpx = ["httpx[http2] (>=0.26.0,<1.0.0)"] quart = ["Quart (>=0.18.0,<1.0.0)", "uvicorn[standard] (>=0.20.0,<1.0.0)"] websockets = ["websockets (>=10.0)"] diff --git a/envs/pydantic-v2/poetry.lock b/envs/pydantic-v2/poetry.lock index 952ae842..884d5fe1 100644 --- a/envs/pydantic-v2/poetry.lock +++ b/envs/pydantic-v2/poetry.lock @@ -1399,13 +1399,13 @@ files = [] develop = true [package.dependencies] -aiohttp = {version = "^3.9.0b0", extras = ["speedups"], optional = true} +aiohttp = {version = "^3.11.0", extras = ["speedups"], optional = true} anyio = "^4.4.0" exceptiongroup = "^1.2.2" fastapi = {version = ">=0.93.0,<1.0.0", optional = true} -httpx = {version = ">=0.20.0,<1.0.0", extras = ["http2"], optional = true} +httpx = {version = ">=0.26.0,<1.0.0", extras = ["http2"], optional = true} loguru = ">=0.6.0,<1.0.0" -pydantic = ">=1.10.0,<3.0.0,!=2.5.0,!=2.5.1,!=2.10.0" +pydantic = ">=1.10.0,<3.0.0,!=2.5.0,!=2.5.1,!=2.10.0,!=2.10.1" pygtrie = "^2.4.1" python-dotenv = ">=0.21.0,<2.0.0" Quart = {version = ">=0.18.0,<1.0.0", optional = true} @@ -1416,10 +1416,10 @@ websockets = {version = ">=10.0", optional = true} yarl = "^1.7.2" [package.extras] -aiohttp = ["aiohttp[speedups] (>=3.9.0b0,<4.0.0)"] -all = ["Quart (>=0.18.0,<1.0.0)", "aiohttp[speedups] (>=3.9.0b0,<4.0.0)", "fastapi (>=0.93.0,<1.0.0)", "httpx[http2] (>=0.20.0,<1.0.0)", "uvicorn[standard] (>=0.20.0,<1.0.0)", "websockets (>=10.0)"] +aiohttp = ["aiohttp[speedups] (>=3.11.0,<4.0.0)"] +all = ["Quart (>=0.18.0,<1.0.0)", "aiohttp[speedups] (>=3.11.0,<4.0.0)", "fastapi (>=0.93.0,<1.0.0)", "httpx[http2] (>=0.26.0,<1.0.0)", "uvicorn[standard] (>=0.20.0,<1.0.0)", "websockets (>=10.0)"] fastapi = ["fastapi (>=0.93.0,<1.0.0)", "uvicorn[standard] (>=0.20.0,<1.0.0)"] -httpx = ["httpx[http2] (>=0.20.0,<1.0.0)"] +httpx = ["httpx[http2] (>=0.26.0,<1.0.0)"] quart = ["Quart (>=0.18.0,<1.0.0)", "uvicorn[standard] (>=0.20.0,<1.0.0)"] websockets = ["websockets (>=10.0)"] diff --git a/nonebot/drivers/aiohttp.py b/nonebot/drivers/aiohttp.py index 0023de7b..d651517a 100644 --- a/nonebot/drivers/aiohttp.py +++ b/nonebot/drivers/aiohttp.py @@ -90,9 +90,7 @@ class Session(HTTPClientSession): @override async def request(self, setup: Request) -> Response: if self._params: - params = self._params.copy() - params.update(setup.url.query) - url = setup.url.with_query(params) + url = setup.url.with_query({**self._params, **setup.url.query}) else: url = setup.url @@ -172,11 +170,13 @@ class Mixin(HTTPClientMixin, WebSocketClientMixin): else: raise RuntimeError(f"Unsupported HTTP version: {setup.version}") + timeout = aiohttp.ClientWSTimeout(ws_close=setup.timeout or 10.0) # type: ignore + async with aiohttp.ClientSession(version=version, trust_env=True) as session: async with session.ws_connect( setup.url, method=setup.method, - timeout=setup.timeout or 10, # type: ignore + timeout=timeout, headers=setup.headers, proxy=setup.proxy, ) as ws: diff --git a/nonebot/drivers/httpx.py b/nonebot/drivers/httpx.py index 15d3f584..c6c015af 100644 --- a/nonebot/drivers/httpx.py +++ b/nonebot/drivers/httpx.py @@ -82,6 +82,8 @@ class Session(HTTPClientSession): data=setup.data, files=setup.files, json=setup.json, + # ensure the params priority + params=setup.url.raw_query_string, headers=tuple(setup.headers.items()), cookies=setup.cookies.jar, timeout=setup.timeout, @@ -102,7 +104,7 @@ class Session(HTTPClientSession): headers=self._headers, cookies=self._cookies.jar, http2=self._version == HTTPVersion.H2, - proxies=self._proxy, + proxy=self._proxy, follow_redirects=True, ) await self._client.__aenter__() diff --git a/poetry.lock b/poetry.lock index 695bace0..931e8a49 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2754,4 +2754,4 @@ websockets = ["websockets"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "9a608f08258ea569245a48676ab5a103a1abee7b4458ed68c4c9c25046445c7f" +content-hash = "d056b0d9257bca0815a57efa5df5f6e3cf88503a7cb54f8de5ca75264cfd25aa" diff --git a/pyproject.toml b/pyproject.toml index 046d0d80..4dc70397 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,13 +34,13 @@ loguru = ">=0.6.0,<1.0.0" python-dotenv = ">=0.21.0,<2.0.0" typing-extensions = ">=4.4.0,<5.0.0" tomli = { version = "^2.0.1", python = "<3.11" } -pydantic = ">=1.10.0,<3.0.0,!=2.5.0,!=2.5.1,!=2.10.0" +pydantic = ">=1.10.0,<3.0.0,!=2.5.0,!=2.5.1,!=2.10.0,!=2.10.1" websockets = { version = ">=10.0", optional = true } Quart = { version = ">=0.18.0,<1.0.0", optional = true } fastapi = { version = ">=0.93.0,<1.0.0", optional = true } -aiohttp = { version = "^3.9.0b0", extras = ["speedups"], optional = true } -httpx = { version = ">=0.20.0,<1.0.0", extras = ["http2"], optional = true } +aiohttp = { version = "^3.11.0", extras = ["speedups"], optional = true } +httpx = { version = ">=0.26.0,<1.0.0", extras = ["http2"], optional = true } uvicorn = { version = ">=0.20.0,<1.0.0", extras = [ "standard", ], optional = true }