Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use port of redirect uri in credential file to run local server in GoogleDocsReader #16327

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Google docs reader."""

import json
import logging
import os
import random
Expand Down Expand Up @@ -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.
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading