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..b87ebbb7743c5 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 @@ -102,6 +103,7 @@ def _get_credentials(self) -> Any: Credentials, the obtained credential. """ creds = None + port = 8080 if os.path.exists("token.json"): creds = Credentials.from_authorized_user_file("token.json", SCOPES) # If there are no (valid) credentials available, let the user log in. @@ -112,7 +114,14 @@ def _get_credentials(self) -> Any: flow = InstalledAppFlow.from_client_secrets_file( "credentials.json", SCOPES ) - creds = flow.run_local_server(port=0) + + with open("credentials.json") 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()) diff --git a/llama-index-integrations/readers/llama-index-readers-google/pyproject.toml b/llama-index-integrations/readers/llama-index-readers-google/pyproject.toml index aaf3adefdeb25..2cce97748e141 100644 --- a/llama-index-integrations/readers/llama-index-readers-google/pyproject.toml +++ b/llama-index-integrations/readers/llama-index-readers-google/pyproject.toml @@ -47,7 +47,7 @@ maintainers = [ ] name = "llama-index-readers-google" readme = "README.md" -version = "0.4.1" +version = "0.4.2" [tool.poetry.dependencies] python = ">=3.10,<4.0"