diff --git a/llama-index-integrations/readers/llama-index-readers-google/llama_index/readers/google/docs/base.py b/llama-index-integrations/readers/llama-index-readers-google/llama_index/readers/google/docs/base.py index affac80454f79..4dc226a795459 100644 --- a/llama-index-integrations/readers/llama-index-readers-google/llama_index/readers/google/docs/base.py +++ b/llama-index-integrations/readers/llama-index-readers-google/llama_index/readers/google/docs/base.py @@ -1,5 +1,6 @@ """Google docs reader.""" +import json import logging import os import random @@ -112,7 +113,15 @@ def _get_credentials(self) -> Any: flow = InstalledAppFlow.from_client_secrets_file( "credentials.json", SCOPES ) - creds = flow.run_local_server(port=0) + + port = 8080 + with open("credentials.json", "r") as json_file: + client_config = json.load(json_file) + redirect_uris = client_config["web"].get("redirect_uris", []) + if len(redirect_uris) > 0: + port = redirect_uris[0].strip("/").split(":")[-1] + + creds = flow.run_local_server(port=port) # Save the credentials for the next run with open("token.json", "w") as token: token.write(creds.to_json())