Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service Account and PyDrive

I would like to use the Google Drive API to store some backups on it using a cronjob. I just don't understand how I can use PyDrive using a Service Account. When I generate the service account file, and I put it in the directory as my script as client_secret.json.

Using this code :

#!/usr/bin/env python
# -*- coding: utf8 -*-


from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

def main():

    gauth = GoogleAuth()
    drive = GoogleDrive(gauth)

    f = drive.CreateFile({'parent': 'toto'})
    f.SetContentFile('test.drive.py')
    f.Upload()

if __name__ == '__main__':
    main(sys.argv[1:])

Result

pydrive.settings.InvalidConfigError: Invalid client secrets file Invalid file format.

Well ok. Then I look at other posts on SO, and find these two :
Automate Verification Process
The code from the first answer on this question returns this :

Traceback (most recent call last):
  File "test.drive.py", line 4, in <module>
    from oauth2client.client import SignedJwtAssertionCredentials
ImportError: cannot import name SignedJwtAssertionCredentials

And then this one :
Automating pydrive verification process
Which just... Doesn't help me much.

Where should I start ? What should I do ? Could someone give me an example with pydrive and Service Authentication just to upload a file ?

EDIT :
After some more research it seems like I needed to install pycrypto to fix the import error described above. I don't know why as it is not specified in the error message.

like image 879
Depado Avatar asked Nov 10 '22 03:11

Depado


1 Answers

After some more research it seems like I needed to install pycrypto to fix the import error described above. I don't know why as it is not specified in the error message.

like image 100
Depado Avatar answered Jan 04 '23 02:01

Depado