Mounting Google Drive on Colab

Viewed 1494

I'm trying to mount my drive on Colab using the following code:

from google.colab import drive
drive._mount('/content/drive')

And I'm getting the following error:

298       # Terminate the DriveFS binary before killing bash.

ValueError: mount failed: invalid oauth code

Tried deleting cookies, restarting the session, but nothing seems to work. I am using a few different google accounts, and only one has a Colab Pro subscription.. but this wasn't an issue till today.

Thanks.

2 Answers

for the moment the only solution that is working right now is this from this similar question but two months ago:

!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
%cd /content
!mkdir drive
%cd drive
!mkdir MyDrive
%cd ..
%cd ..
!google-drive-ocamlfuse /content/drive/MyDrive

Let's hope the normal way drive.mount will be fixed soon !

Here is the solution you can try:

As of new (messed up) update you can not mount using drive._mount anymore (or at least for now). So what you can do is either copy your folder/directory from your other google drive to your current google drive (the account you are log in to colab with) OR you can simply log out from colab and log in with your google account that has the drive you want to mount to

Remember use drive.mount and not drive._mount after following the above guideline

Related