Fix: use build(credentials=creds) instead of creds.authorize() for google-auth compatibility; add traceback logging

This commit is contained in:
daniel
2026-05-08 19:57:35 -05:00
parent 9b56aa83df
commit eddbd98153
7 changed files with 24 additions and 62 deletions

View File

@@ -8,6 +8,7 @@ Credential secret: agent-claw/google-credentials/{actor_id.replace(':', '-')}
Contains: token, refresh_token, token_uri, client_id, client_secret, scopes
"""
import json
import traceback
import boto3
import httplib2
from strands import tool
@@ -77,11 +78,10 @@ _current_actor_id: str = ''
def _svc(api: str, version: str, creds: Credentials):
# Pass ONLY the authorized http (with timeout) — do NOT also pass credentials.
# When both http= and credentials= are given, google-api-python-client creates a
# new un-timed Http() from credentials for API calls, ignoring our timeout.
http = creds.authorize(httplib2.Http(timeout=_HTTP_TIMEOUT))
return build(api, version, http=http, cache_discovery=False)
# Standard google-auth pattern: pass credentials= directly to build().
# google.oauth2.credentials.Credentials is natively supported by googleapiclient.
# (creds.authorize() is oauth2client only — not available here)
return build(api, version, credentials=creds, cache_discovery=False)
@tool
@@ -98,6 +98,8 @@ def list_calendars() -> str:
for c in items
)
except Exception as e:
tb = traceback.format_exc()
print(f'[google] list_calendars error: {e}\n{tb}')
return f'Error listing calendars: {e}'
@@ -145,6 +147,8 @@ def get_calendar_events(
lines.append(f'- "{e.get("summary", "No Title")}" (Starts: {start}, Ends: {end}) ID: {eid}')
return f'Retrieved {len(events)} events from "{calendar_id}":\n' + '\n'.join(lines)
except Exception as e:
tb = traceback.format_exc()
print(f'[google] get_calendar_events error: {e}\n{tb}')
return f'Error fetching calendar events: {e}'
@@ -177,6 +181,8 @@ def list_gmail_messages(max_results: int = 10, query: str = 'in:inbox') -> str:
out += f'\n(more results available)'
return out
except Exception as e:
tb = traceback.format_exc()
print(f'[google] list_gmail_messages error: {e}\n{tb}')
return f'Error listing Gmail messages: {e}'