12

I tried to mount my drive in Google Colab, but, I can't do it because of credential error.

I want to mount another drive different from the one I am using in Google Colab.

The following is my commands.

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

The following is the part of question.

MessageError                              Traceback (most recent call last)
<ipython-input-1-d5df0069828e> in <module>()
      1 from google.colab import drive
----> 2 drive.mount('/content/drive')

3 frames
/usr/local/lib/python3.7/dist-packages/google/colab/drive.py in mount(mountpoint, 
force_remount, timeout_ms, use_metadata_server)
    111       timeout_ms=timeout_ms,
    112       use_metadata_server=use_metadata_server,
--> 113       ephemeral=ephemeral)
    114 
    115 

/usr/local/lib/python3.7/dist-packages/google/colab/drive.py in _mount(mountpoint, 
force_remount, timeout_ms, use_metadata_server, ephemeral)
    134   if ephemeral:
    135     _message.blocking_request(
--> 136         'request_auth', request={'authType': 'dfs_ephemeral'}, timeout_sec=None)
    137 
    138   mountpoint = _os.path.expanduser(mountpoint)

/usr/local/lib/python3.7/dist-packages/google/colab/_message.py in 
blocking_request(request_type, request, timeout_sec, parent)
    173   request_id = send_request(
    174       request_type, request, parent=parent, expect_reply=True)
--> 175   return read_reply_from_input(request_id, timeout_sec)

/usr/local/lib/python3.7/dist-packages/google/colab/_message.py in 
read_reply_from_input(message_id, timeout_sec)
    104         reply.get('colab_msg_id') == message_id):
    105       if 'error' in reply:
--> 106         raise MessageError(reply['error'])
    107       return reply.get('data', None)
    108 

MessageError: Error: credential propagation was unsuccessful

I could mount another drive yesterday to do the same method.

What is the solution?

BraveSugar
  • 243
  • 1
  • 2
  • 9
  • This problem is happened when I used Colab Pro+ account. When I use free Colab Account, I can mount another drive. So, I think this problem is caused by Colab Pro+. – BraveSugar Nov 05 '21 at 01:54

6 Answers6

12

I solved this problem with this link. The following is the correct code:

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

Here is the screenshot of the code:

The screenshot of the solution

Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
BraveSugar
  • 243
  • 1
  • 2
  • 9
  • 1
    It worked until yesterday. I got 2 3 from google.colab import drive ----> 4 drive._mount('/content/drive') 5 6 # !apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python /usr/local/lib/python3.7/dist-packages/google/colab/drive.py in _mount(mountpoint, force_remount, timeout_ms, use_metadata_server, ephemeral) 295 elif case == 5 and not use_metadata_server: --> 296 raise ValueError('mount failed: invalid oauth code') ValueError: mount failed: invalid oauth code – jerron Jan 21 '22 at 06:33
  • Now, this solution is not working. – BraveSugar Jan 28 '22 at 02:59
  • Not working anymore – Partho KR Jan 29 '22 at 14:47
  • anyone tried this recently, it seemed to hang at sudo add-apt-repository -y ppa:alessandro-strada/ppa – kawingkelvin Nov 14 '22 at 17:14
5

Update: From Mars 30, 2022, my old solution isn't working! I find another solution (Phillip's solution) that is working now.

Phillip's Solution:

This solution is based on Phillip's post. You can follow his post for more information.

Follow these steps:

  1. Run the below code:
!sudo add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!sudo apt-get update -qq 2>&1 > /dev/null
!sudo apt -y install -qq google-drive-ocamlfuse 2>&1 > /dev/null
!google-drive-ocamlfuse
  1. From the previous step, you get an error like this. Click on the link that locates in the previous error message and authenticate your account.

Failure("Error opening URL:https://accounts.google.com/o/oauth2/auth?client_id=... ")

  1. Run the below code:
!sudo apt-get install -qq w3m # to act as web browser 
!xdg-settings set default-web-browser w3m.desktop # to set default browser
%cd /content
!mkdir drive
%cd drive
!mkdir MyDrive
%cd ..
%cd ..
!google-drive-ocamlfuse /content/drive/MyDrive

You must get this message:

Access token retrieved correctly.

My Old Solution

!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
Alireza Mazochi
  • 897
  • 1
  • 15
  • 22
5

As of now (26th January 2022), you can not mount another drive with different goggle account in Colab with drive.mount() or drive._mount(). Previously it could be done.

Now, You may use gdrive package instead. Check my detailed answer in this thread

Abrar_11648
  • 368
  • 4
  • 7
1

I have a workaround, you could share folder from one drive account to another and after that you should create shortcut. After that use regular mount

0

Just copy and paste the code given below: -

#Connect Google Drive
from google.colab import drive
drive._mount('/content/drive')
Maheep
  • 767
  • 10
  • 6
0

Login in chrome with the user that you want to connect to drive, don't select another account and It works for me.

Zaha
  • 846
  • 10
  • 21