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

GoogleDriveLoader creates random ports #168

Open
Oni22 opened this issue Apr 19, 2024 · 1 comment
Open

GoogleDriveLoader creates random ports #168

Oni22 opened this issue Apr 19, 2024 · 1 comment

Comments

@Oni22
Copy link

Oni22 commented Apr 19, 2024

Hi everyone,

I started to work with the GoogleDriveLoader() and I recognized that there might be an issue with the oauth flow. Let's assume the following setup:

.env file:
GOOGLE_APPLICATION_CREDENTIALS=""

main.py:

loader = GoogleDriveLoader(
        folder_id="XXXXX",
        credentials_path="XXXX/google_credentials.json",
        token_path="XXXX/google_token.json",
        recursive=False,
    )

With this setup, the GoogleDriveLoader() creates a local auth server during local development that always uses a random port. This leads to the problem that my redirect url that I configured in the Google Cloud never works. So I'm wondering why this class creates a local server and if so, why can't we set the port ourselves?

The code which creates this behavior is in line 191:

        if not creds or not creds.valid:
            if creds and creds.expired and creds.refresh_token:
                creds.refresh(Request())
            elif "GOOGLE_APPLICATION_CREDENTIALS" not in os.environ:
                creds, project = default()
                creds = creds.with_scopes(SCOPES)
                # no need to write to file
                if creds:
                    return creds
            else:
                flow = InstalledAppFlow.from_client_secrets_file(
                    str(self.credentials_path), SCOPES
                )
              # Why do we set port 0 -> leads to random port? 
             # Why do we create a local server?
                creds = flow.run_local_server(port=0) 
            with open(self.token_path, "w") as token:
                token.write(creds.to_json())

I can solve this issue by setting the port to my preffered one eg 8080. Anyone who has an idea?

@lkuligin
Copy link
Collaborator

let's maybe add a parameters with a default value, and throw a meaningful erorr description if the port is occupied?
it would be awesome if you could work on that, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants