iterative / PyDrive2

Google Drive API Python wrapper library. Maintained fork of PyDrive.
https://docs.iterative.ai/PyDrive2
Other
581 stars 69 forks source link

Stuck on authenthicating #177

Closed patricialorenzoc closed 2 years ago

patricialorenzoc commented 2 years ago

Hello, i'm trying to use PyDrive2 to link Kaggle to my Google Drive, i've followed the authenthication quickstart from the documentation but i'm stuck on authenthicating, i have a settings.yaml with the following code:

client_config_backend: file
client_config_file: client_secrets.json

save_credentials: True
save_credentials_backend: file
save_credentials_file: credentials.json

get_refresh_token: True

oauth_scope: 
  - https://www.googleapis.com/auth/drive
  - https://www.googleapis.com/auth/drive.file
  - https://www.googleapis.com/auth/drive.install
  - https://www.googleapis.com/auth/drive.readonly

I have both client_secrets.json and credentials.json created and i was trying to use the following code to download the contents of a folder:

import os
from pydrive2.auth import GoogleAuth
from pydrive2.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)

file_list = drive.ListFile( {'q': {secret_value_1} + " in parents"}).GetList()  

for f in file_list:
    print('title: %s, id: %s' % (f['title'], f['id']))
    fname = f['title']
    print('downloading to {}'.format(fname))
    f_ = drive.CreateFile({'id': f['id']})
    f_.GetContentFile(fname)

So i run this code and it gives me a link to open and authenthicate like this: imagen

So i follow with the authenthication but instead of giving me an error or succeeding it gives me a listing of the contents of the folder and i don't know how to fix this.

I'm using pythons http.server to launch on ports 8080or 8090 as a local server. Is using this the problem?

shcheklein commented 2 years ago

Hi @patricialorenzoc !

I'm using pythons http.server to launch on ports 8080 or 8090 as a local server. Is using this the problem?

If everything is setup correctly you don't need it. LocalWebserverAuth should be running it for you internally.

it gives me a listing of the contents of the folder and i don't know how to fix this.

can you give a bit more details, how does it look like?

Hello, i'm trying to use PyDrive2 to link Kaggle to my Google Drive

How and where do you run it?

My feeling is that you should not be using LocalWebserverAuth at at all, or run it locally first and then move the credentials.json to a remote machine. Or use CommandLineAuth instead or service account (recommended).

patricialorenzoc commented 2 years ago

Hi @patricialorenzoc !

I'm using pythons http.server to launch on ports 8080 or 8090 as a local server. Is using this the problem?

If everything is setup correctly you don't need it. LocalWebserverAuth should be running it for you internally.

I tried to do this without running de server but had other problems initially that i explained in this post.

it gives me a listing of the contents of the folder and i don't know how to fix this.

can you give a bit more details, how does it look like?

This is what it looks like.

imagen

Hello, i'm trying to use PyDrive2 to link Kaggle to my Google Drive

How and where do you run it?

I use individual cells in Kaggle that i can run in case i want to test something in particular.

My feeling is that you should not be using LocalWebserverAuth at at all, or run it locally first and then move the credentials.json to a remote machine. Or use CommandLineAuth instead or service account (recommended).

If i try to use CommandLineAuth instead i get another error, this one: imagen

shcheklein commented 2 years ago

Closing as stale