Google Colab - Google Drive can´t be mounted anymore - Browser Popup (Google Drive for Desktop) instead of Link in the code output for authorization

Viewed 23359

Since yesterday I have had the problem that I can no longer mount my Google account. Normally, when I run it, I get a link to authorize myself with. Now, when the code is executed, an extra browser window is opened where I should authorize myself. But if I do it over it, it doesn't work. Do you know why it can be that this authorization link is suddenly no longer shown? Any security setting maybe? I've tried several browsers.

EDIT: With the new authorization popup it works if i mount the google drive from the same google account like colab. But the problem is that my main google drive is on another account than Google Colab. With the link it used to work without any problems earlier...

EDIT 2: I have now solved it in such a way that I have shared the required folder for my other account and can now access it via my Colab Google Drive account. But I still didn't manage to get the link back.

After the code execution and authorization with the new popup i get this error message on Google Colab:

MessageError Traceback (most recent call last) in () 1 #Connect Google Drive 2 from google.colab import drive ----> 3 drive.mount('/gdrive')

3 frames /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 use this code:

#Connect Google Drive
from google.colab import drive
drive.mount('/gdrive')

Authorization popup instead of the link in the code output

6 Answers

Update: Unfortunately, From Jan 20, 2022, The small solution based on Blue's solution and the similar solutions isn't working anymore (Reference). You can use my old solution again...

Update2: From Mars 30, 2022, my old solution isn't working too! 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

Blue's Solution

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

It is due to the new policy. If your acc mounted is different Colab acc, please use the syntax to make it work.

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

This is a problem with Google Colab Pro. I have a Pro account as well as a normal account. My normal account works as intended (with the link) whereas my Pro account has the pop-up window that gives me the same error as OP.

this solution could be redundant, as i didn't get whether you solved your problem or not... so, share both folders in destination gdrive & gdrive you run colabpro, then add shortcut to drive from destination to running gdrive, set the code on running gdrive to call added shortcut folder name and run the code "locally". this way colabpro will execute the code on running account and store the results on destination drive you chose. it's all the same as setting destination account via authorization code, which doesn't work anymore, obviously. and a note, when creating shortcut, it may be 5-10min before it's visible in running account. hope it helps. cheers! ^^

you can mount drive acount which is same with colab acount or you can use drive._mount('/content/drive')

Related