From f36e9c5cc2b9644a28e4a8015a2906d72252ca51 Mon Sep 17 00:00:00 2001 From: student_2333 Date: Fri, 16 Feb 2024 21:26:14 +0800 Subject: [PATCH] :bug: Fix: pydantic v2 `URL` support (#93) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- nonebot/adapters/onebot/v11/adapter.py | 3 ++- nonebot/adapters/onebot/v12/adapter.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nonebot/adapters/onebot/v11/adapter.py b/nonebot/adapters/onebot/v11/adapter.py index 3376b4f7..5e301cd6 100644 --- a/nonebot/adapters/onebot/v11/adapter.py +++ b/nonebot/adapters/onebot/v11/adapter.py @@ -149,7 +149,7 @@ async def _call_api(self, bot: Bot, api: str, **data: Any) -> Any: raise NetworkError(f"WebSocket call api {api} timeout") from None elif isinstance(self.driver, HTTPClientMixin): - api_root = self.onebot_config.onebot_api_roots.get(bot.self_id) + api_root = str(self.onebot_config.onebot_api_roots.get(bot.self_id)) if not api_root: raise ApiNotAvailable elif not api_root.endswith("/"): @@ -298,6 +298,7 @@ def _check_access_token(self, request: Request) -> Optional[Response]: async def _start_forward(self) -> None: for url in self.onebot_config.onebot_ws_urls: + url = str(url) try: ws_url = URL(url) self.tasks.append(asyncio.create_task(self._forward_ws(ws_url))) diff --git a/nonebot/adapters/onebot/v12/adapter.py b/nonebot/adapters/onebot/v12/adapter.py index 50787b8f..42433f3c 100644 --- a/nonebot/adapters/onebot/v12/adapter.py +++ b/nonebot/adapters/onebot/v12/adapter.py @@ -201,7 +201,7 @@ async def _call_api(self, bot: Bot, api: str, **data: Any) -> Any: raise NetworkError(f"WebSocket call api {api} timeout") from None elif isinstance(self.driver, HTTPClientMixin): - api_url = self.onebot_config.onebot_api_roots.get(bot.self_id) + api_url = str(self.onebot_config.onebot_api_roots.get(bot.self_id)) if not api_url: raise ApiNotAvailable @@ -414,6 +414,7 @@ def _check_access_token(self, request: Request) -> Optional[Response]: async def _start_forward(self) -> None: for url in self.onebot_config.onebot_ws_urls: + url = str(url) try: ws_url = URL(url) self.tasks.append(asyncio.create_task(self._forward_ws(ws_url)))