diff --git a/httpx/_client.py b/httpx/_client.py index 2249231f8c..b728670a8b 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -659,6 +659,7 @@ def __init__( transport: BaseTransport | None = None, default_encoding: str | typing.Callable[[bytes], str] = "utf-8", ) -> None: + http2 = False # 强制不使用http2 super().__init__( auth=auth, params=params, @@ -672,7 +673,7 @@ def __init__( trust_env=trust_env, default_encoding=default_encoding, ) - + if http2: try: import h2 # noqa @@ -694,6 +695,7 @@ def __init__( limits=limits, transport=transport, ) + http2=False self._mounts: dict[URLPattern, BaseTransport | None] = { URLPattern(key): None if proxy is None @@ -725,6 +727,7 @@ def _init_transport( limits: Limits = DEFAULT_LIMITS, transport: BaseTransport | None = None, ) -> BaseTransport: + http2=False if transport is not None: return transport @@ -747,6 +750,7 @@ def _init_proxy_transport( http2: bool = False, limits: Limits = DEFAULT_LIMITS, ) -> BaseTransport: + http2=False return HTTPTransport( verify=verify, cert=cert, @@ -1373,6 +1377,7 @@ def __init__( trust_env: bool = True, default_encoding: str | typing.Callable[[bytes], str] = "utf-8", ) -> None: + http2 = False super().__init__( auth=auth, params=params, @@ -1439,6 +1444,7 @@ def _init_transport( limits: Limits = DEFAULT_LIMITS, transport: AsyncBaseTransport | None = None, ) -> AsyncBaseTransport: + http2 = False if transport is not None: return transport @@ -1461,6 +1467,7 @@ def _init_proxy_transport( http2: bool = False, limits: Limits = DEFAULT_LIMITS, ) -> AsyncBaseTransport: + http2 = False return AsyncHTTPTransport( verify=verify, cert=cert,