Skip to content

Commit a842721

Browse files
sararobcopybara-github
authored andcommitted
fix: Fix google.auth.transport.requests import error in Live API
PiperOrigin-RevId: 838758702
1 parent 99058b6 commit a842721

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

google/genai/live.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
from websockets.client import ClientConnection # type: ignore
5151
from websockets.client import connect as ws_connect # type: ignore
5252

53+
try:
54+
from google.auth.transport import requests
55+
except ImportError:
56+
requests = None # type: ignore[assignment]
57+
5358
if typing.TYPE_CHECKING:
5459
from mcp import ClientSession as McpClientSession
5560
from mcp.types import Tool as McpTool
@@ -1027,7 +1032,9 @@ async def connect(
10271032
# creds.valid is False, and creds.token is None
10281033
# Need to refresh credentials to populate those
10291034
if not (creds.token and creds.valid):
1030-
auth_req = google.auth.transport.requests.Request() # type: ignore
1035+
if requests is None:
1036+
raise ValueError('The requests module is required to refresh google-auth credentials. Please install with `pip install google-auth[requests]`')
1037+
auth_req = requests.Request() # type: ignore
10311038
creds.refresh(auth_req)
10321039
bearer_token = creds.token
10331040

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ classifiers = [
2626
]
2727
dependencies = [
2828
"anyio>=4.8.0, <5.0.0",
29-
"google-auth>=2.14.1, <3.0.0",
29+
"google-auth[requests]>=2.14.1, <3.0.0",
3030
"httpx>=0.28.1, <1.0.0",
3131
"pydantic>=2.9.0, <3.0.0",
3232
"requests>=2.28.1, <3.0.0",

0 commit comments

Comments
 (0)