mirror of
https://github.com/nonebot/nonebot2.git
synced 2026-04-18 14:55:43 +00:00
🐛 Fix: 修正 http/websocket client timeout (#3923)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -9,6 +9,7 @@ from .abstract import ReverseDriver as ReverseDriver
|
||||
from .abstract import ReverseMixin as ReverseMixin
|
||||
from .abstract import WebSocketClientMixin as WebSocketClientMixin
|
||||
from .combine import combine_driver as combine_driver
|
||||
from .model import DEFAULT_TIMEOUT as DEFAULT_TIMEOUT
|
||||
from .model import URL as URL
|
||||
from .model import ContentTypes as ContentTypes
|
||||
from .model import Cookies as Cookies
|
||||
|
||||
@@ -19,7 +19,13 @@ from nonebot.typing import (
|
||||
T_BotDisconnectionHook,
|
||||
T_DependencyCache,
|
||||
)
|
||||
from nonebot.utils import escape_tag, flatten_exception_group, run_coro_with_catch
|
||||
from nonebot.utils import (
|
||||
UNSET,
|
||||
UnsetType,
|
||||
escape_tag,
|
||||
flatten_exception_group,
|
||||
run_coro_with_catch,
|
||||
)
|
||||
|
||||
from ._lifespan import LIFESPAN_FUNC, Lifespan
|
||||
from .model import (
|
||||
@@ -246,7 +252,7 @@ class HTTPClientSession(abc.ABC):
|
||||
headers: HeaderTypes = None,
|
||||
cookies: CookieTypes = None,
|
||||
version: str | HTTPVersion = HTTPVersion.H11,
|
||||
timeout: TimeoutTypes = None,
|
||||
timeout: TimeoutTypes | UnsetType = UNSET,
|
||||
proxy: str | None = None,
|
||||
):
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -9,14 +9,20 @@ import urllib.request
|
||||
from multidict import CIMultiDict
|
||||
from yarl import URL as URL
|
||||
|
||||
from nonebot.utils import UNSET, UnsetType
|
||||
|
||||
|
||||
@dataclass
|
||||
class Timeout:
|
||||
"""Request 超时配置。"""
|
||||
|
||||
total: float | None = None
|
||||
connect: float | None = None
|
||||
read: float | None = None
|
||||
total: float | None | UnsetType = UNSET
|
||||
connect: float | None | UnsetType = UNSET
|
||||
read: float | None | UnsetType = UNSET
|
||||
close: float | None | UnsetType = UNSET
|
||||
|
||||
|
||||
DEFAULT_TIMEOUT = Timeout(total=None, connect=5.0, read=30.0, close=10.0)
|
||||
|
||||
|
||||
RawURL: TypeAlias = tuple[bytes, bytes, int | None, bytes]
|
||||
@@ -68,7 +74,7 @@ class Request:
|
||||
json: Any = None,
|
||||
files: FilesTypes = None,
|
||||
version: str | HTTPVersion = HTTPVersion.H11,
|
||||
timeout: TimeoutTypes = None,
|
||||
timeout: TimeoutTypes | UnsetType = UNSET,
|
||||
proxy: str | None = None,
|
||||
):
|
||||
# method
|
||||
@@ -80,7 +86,7 @@ class Request:
|
||||
# http version
|
||||
self.version: HTTPVersion = HTTPVersion(version)
|
||||
# timeout
|
||||
self.timeout: TimeoutTypes = timeout
|
||||
self.timeout: TimeoutTypes | UnsetType = timeout
|
||||
# proxy
|
||||
self.proxy: str | None = proxy
|
||||
|
||||
|
||||
Reference in New Issue
Block a user