diff --git a/sdk/python/packages/flet/pyproject.toml b/sdk/python/packages/flet/pyproject.toml index 9fb0df02f5..2d0cf39474 100644 --- a/sdk/python/packages/flet/pyproject.toml +++ b/sdk/python/packages/flet/pyproject.toml @@ -10,7 +10,11 @@ dependencies = [ "flet-cli; extra == 'cli'", "flet-web; extra == 'web'", "oauthlib >=3.2.2; platform_system != 'Emscripten'", - "httpx >=0.28.1; platform_system != 'Emscripten'", + "httpx2 >=2.12.0; platform_system != 'Emscripten'", + # Required by the packaged-app bootstrap (templates/build/*/lib/python.dart), + # which imports certifi unconditionally to configure the CA bundle. It used + # to arrive transitively via httpx; httpx2 no longer depends on it. + "certifi >=2024.2.2; platform_system != 'Emscripten'", "repath >=0.9.0", "msgpack >=1.1.0", "typing-extensions; python_version < '3.11'" diff --git a/sdk/python/packages/flet/src/flet/auth/authorization_service.py b/sdk/python/packages/flet/src/flet/auth/authorization_service.py index 8dbfca5048..ed83d03e01 100644 --- a/sdk/python/packages/flet/src/flet/auth/authorization_service.py +++ b/sdk/python/packages/flet/src/flet/auth/authorization_service.py @@ -114,9 +114,9 @@ async def request_token(self, code: str): code: Provider-issued authorization code returned to redirect URL. Raises: - httpx.HTTPStatusError: If token endpoint returns a non-success status. + httpx2.HTTPStatusError: If token endpoint returns a non-success status. """ - import httpx + import httpx2 from oauthlib.oauth2 import WebApplicationClient client = WebApplicationClient(self.provider.client_id) @@ -129,10 +129,10 @@ async def request_token(self, code: str): ) headers = self.__get_default_headers() headers["content-type"] = "application/x-www-form-urlencoded" - req = httpx.Request( + req = httpx2.Request( "POST", self.provider.token_endpoint, content=data, headers=headers ) - async with httpx.AsyncClient(follow_redirects=True) as client: + async with httpx2.AsyncClient(follow_redirects=True) as client: resp = await client.send(req) resp.raise_for_status() client = WebApplicationClient(self.provider.client_id) @@ -193,7 +193,7 @@ async def __refresh_token(self): or does not include a refresh token. Raises: - httpx.HTTPStatusError: If the refresh request fails. + httpx2.HTTPStatusError: If the refresh request fails. """ if ( @@ -204,7 +204,7 @@ async def __refresh_token(self): ): return None - import httpx + import httpx2 from oauthlib.oauth2 import WebApplicationClient assert self.__token is not None @@ -217,11 +217,11 @@ async def __refresh_token(self): ) headers = self.__get_default_headers() headers["content-type"] = "application/x-www-form-urlencoded" - refresh_req = httpx.Request( + refresh_req = httpx2.Request( "POST", url=self.provider.token_endpoint, content=data, headers=headers ) if refresh_req: - async with httpx.AsyncClient(follow_redirects=True) as client: + async with httpx2.AsyncClient(follow_redirects=True) as client: refresh_resp = await client.send(refresh_req) refresh_resp.raise_for_status() assert self.__token is not None @@ -240,16 +240,16 @@ async def __get_user(self) -> User: `provider.user_id_fn`. Raises: - httpx.HTTPStatusError: If user endpoint request fails. + httpx2.HTTPStatusError: If user endpoint request fails. """ - import httpx + import httpx2 assert self.__token is not None assert self.provider.user_endpoint is not None headers = self.__get_default_headers() headers["Authorization"] = f"Bearer {self.__token.access_token}" - user_req = httpx.Request("GET", self.provider.user_endpoint, headers=headers) - async with httpx.AsyncClient(follow_redirects=True) as client: + user_req = httpx2.Request("GET", self.provider.user_endpoint, headers=headers) + async with httpx2.AsyncClient(follow_redirects=True) as client: user_resp = await client.send(user_req) user_resp.raise_for_status() assert self.provider.user_id_fn is not None diff --git a/sdk/python/packages/flet/src/flet/auth/providers/github_oauth_provider.py b/sdk/python/packages/flet/src/flet/auth/providers/github_oauth_provider.py index 9c261676f7..6f55b5b64e 100644 --- a/sdk/python/packages/flet/src/flet/auth/providers/github_oauth_provider.py +++ b/sdk/python/packages/flet/src/flet/auth/providers/github_oauth_provider.py @@ -38,11 +38,11 @@ async def _fetch_groups(self, access_token: str) -> list[Group]: Returns: A list of :class:`~flet.auth.Group` mapped from `/user/teams`. """ - import httpx + import httpx2 - async with httpx.AsyncClient(follow_redirects=True) as client: + async with httpx2.AsyncClient(follow_redirects=True) as client: teams_resp = await client.send( - httpx.Request( + httpx2.Request( "GET", "https://api.github.com/user/teams", headers=self.__get_client_headers(access_token), @@ -71,11 +71,11 @@ async def _fetch_user(self, access_token: str) -> Optional[User]: A :class:`~flet.auth.User` built from `/user`; its `email` is populated from the primary address in `/user/emails` when available. """ - import httpx + import httpx2 - async with httpx.AsyncClient(follow_redirects=True) as client: + async with httpx2.AsyncClient(follow_redirects=True) as client: user_resp = await client.send( - httpx.Request( + httpx2.Request( "GET", "https://api.github.com/user", headers=self.__get_client_headers(access_token), @@ -85,7 +85,7 @@ async def _fetch_user(self, access_token: str) -> Optional[User]: uj = json.loads(user_resp.text) emails_resp = await client.send( - httpx.Request( + httpx2.Request( "GET", "https://api.github.com/user/emails", headers=self.__get_client_headers(access_token),