Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't mount my another drive in Google Colab

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?

like image 800
BraveSugar Avatar asked Nov 03 '21 04:11

BraveSugar


3 Answers

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

like image 149
BraveSugar Avatar answered Sep 18 '22 19:09

BraveSugar


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

like image 37
Abrar_11648 Avatar answered Sep 20 '22 19:09

Abrar_11648


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
like image 26
Alireza Mazochi Avatar answered Sep 21 '22 19:09

Alireza Mazochi