5

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.

Community
  • 1
  • 1
Depado
  • 4,811
  • 3
  • 41
  • 63
  • Have you figured out how to use it ? If you have a code example that you could put as an answer that would be great as I'm currently trying to do the same thing ! – Etienne Noël Dec 04 '14 at 18:08
  • As I wrote in my question, I needed to install `pycrypto` for this to work. Though I stopped spending time on this, so I can't help you any further... – Depado Jan 26 '15 at 16:48
  • How did you create your client_secrets.json ? – The Windwaker Nov 30 '15 at 17:18
  • @TheWindwaker See https://developers.google.com/api-client-library/python/guide/aaa_client_secrets – Depado Dec 01 '15 at 09:02
  • @Depado I just wanted to know how did YOU create it, you might have chosen wrong settings while creating it – The Windwaker Dec 02 '15 at 10:23
  • @TheWindwaker I should answer my own question. The only thing I needed for this code to work was to install PyCrypto as specified in my last edit. The problem did not come from the `client_secrets.json` – Depado Dec 02 '15 at 11:31

1 Answers1

1

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.

Depado
  • 4,811
  • 3
  • 41
  • 63