3

I found this great question here: https://stackoverflow.com/questions/48376580/google-colab-how-to-read-data-from-my-google-drive which helped me to connect the colab to my drive

Here it is as well:

from google.colab import drive 
drive.mount('/content/gdrive')

My question: Is there anyway to do this process of the google authentication only once? Colab disconnects from time to time if not in use and than I need to restart the authentication process.

Thanks

Giladbi
  • 1,692
  • 3
  • 15
  • 29

2 Answers2

3

Authentication is done per machine; exchanging keys to access drive. Since you always get a new machine on re-connect, you need to re-authenticate.

However, another option is to use an API key for your google drive access. This can be done via theGoogle API Console for the Drive Platform. Essentially you would have one API Token you can over and over again; possibly leading you to store it inside the notebook... where the bad part starts.

If you opt-in on using a token to "manually" mount the drive folder, as soon someone gets a hand on this token (i.e. sharing your notebook, man in the middle, forgetting to delete the key), your drive folder is compromised. That is the reason why my formal answer to this question is: No, you can't.

But since colab provides the whole machine with a unix environment where you can execute arbitrary bash commands, you are in control and leave you with additional resources for further investigation:

Dino
  • 192
  • 7
2

A recently released feature makes this much simpler. The details are described in this answer: https://stackoverflow.com/a/60103029/8841057

The short version is that for notebooks in Drive that aren't shared, there's now a GUI option to mount Drive files automatically for a given notebook.

Bob Smith
  • 26,929
  • 9
  • 72
  • 69