35

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

Tim
  • 463
  • 1
  • 4
  • 7
  • 1
    Nobody with the same problem? The main problem here is that when executing the code he wants to authorize himself with "Google Drive for Desktop" in a separate browser window instead of simply outputting a link. Can't you possibly switch off somewhere that it authenticates itself via this path maybe? – Tim Nov 04 '21 at 09:49
  • 1
    I am facing the same problem! – belal_bh Nov 05 '21 at 13:48
  • I was answering but then saw your EDIT :) I recommend you post it as an answer as it would be helpful to others. I faced the same problem but didn't find a way to use it from different accounts. Before it was asking permissions for Google Stream, and now for Google Drive, so something must have change in the way it deals with permissions – Francisco Cruz Nov 07 '21 at 16:48
  • Hi Francisco, yes it works if i mount the google drive from the same google account, but the problem is, that all my files are on another common account. I have now solved it in such a way that I have released the required folder for my other account and can now access it via my Colab Google Drive account. But I didn't manage to get the link back. – Tim Nov 08 '21 at 20:42

6 Answers6

44

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')
Alireza Mazochi
  • 897
  • 1
  • 15
  • 22
  • 1
    Hi there, interesting solution! I have now solved it in such a way that I have released the required folder for my other account and can now access it via my Colab Google Drive account. – Tim Nov 08 '21 at 20:46
  • @Tim, Hi again. Does it mean you share your folder in the drive account with the running account? Or you place a copy of your folder in another account? – Alireza Mazochi Nov 09 '21 at 06:06
  • Hmm but there seems to be some problems with this code: E: Package 'python-software-properties' has no installation candidate. Please enter the verification code: Access token retrieved correctly. /content mkdir: cannot create directory ‘drive’: File exists /content/drive mkdir: cannot create directory ‘MyDrive’: File exists /content / – Tim Nov 09 '21 at 09:15
  • Works it for you without problems? Oh and yes, I just share the folder with my Google Colab Drive account at the moment. I can connect to the Google Drive account of the same account via the login mask. – Tim Nov 09 '21 at 10:48
  • @Tim, Yes it works for me! Please terminate the current session and run again this code as the first cell. It is possible you connected to Drive at now (because you got "File exists") or even it is possible you have changed the path of the command line. Like you, I got "E: Package 'python-software-properties' has no installation candidate" but it isn't important. You can remove the first line of this code ( I will remove this line if other things are OK) Don't forget this code needs two times entering a verification code. – Alireza Mazochi Nov 09 '21 at 11:29
  • 1
    Hi Alireza, yes it worked if i entering the verification code twice :) – Tim Nov 09 '21 at 18:03
  • Looks like this solution has now stopped working... any ideas? – Fidel I. Schaposnik Jan 20 '22 at 22:23
  • @FidelI.Schaposnik You are right. Perhaps it is a temporary problem. I tested my "Old Solution" now and this is working. If I find a proper solution, I will update my answer. – Alireza Mazochi Jan 21 '22 at 07:19
  • how did u come up with this solution ? – yagna thakkar Feb 04 '22 at 05:08
  • @yagnathakkar Hi. I use this answer and applied some changes: https://stackoverflow.com/a/57394402/8961642 – Alireza Mazochi Feb 05 '22 at 16:55
  • Old method stopped working too. No drive gets mounted, even though the authentication is completed – blkpingu Mar 17 '22 at 13:35
  • Hi @blkpingu . Are you sure?! I checked it now and this works well. Don't forget this method requires two code entering steps. – Alireza Mazochi Mar 17 '22 at 15:33
  • No longer works for me (Mar. 30, 2022)... – yyFred Mar 31 '22 at 03:29
  • @yyFred Yes. You are right. I updated my solution. – Alireza Mazochi Apr 01 '22 at 09:49
  • @AlirezaMazochi I tried your latest solution and it worked mounting gdrive. However, from google.colab import auth; auth.authenticate_user() is encountering the same error (a popup), and it will fail if you use your other google account in the same way. Any idea how to solve? i need this to up/download from my GCP bucket. – kawingkelvin Apr 06 '22 at 23:44
  • Hi @kawingkelvin. Unfortunately, I haven't any information about Google Cloud and details of connecting to it. I tested the latest solution only for Google Drive. – Alireza Mazochi Apr 07 '22 at 06:19
  • 1
    worked like a charm as of 21-May-2022 – Shaida Muhammad May 21 '22 at 05:06
  • Anyone tried this late Aug/2022, doesn't seem to work – kawingkelvin Aug 25 '22 at 18:08
  • Hi @kawingkelvin. I tested it now (Sep/2022) and it works like previously. – Alireza Mazochi Sep 12 '22 at 06:33
  • 1
    Phillip's solution worked!!! For people who still have problems even with the solution, make sure to perform it on Chrome! I was using Firefox and Drive auth always failed! – Dan Jun 18 '23 at 06:22
15

[Edit] This is not working anymore as google has removed this feature. https://github.com/googlecolab/colabtools/issues/2562#issuecomment-1017869732

I have this issue also. But this solve the issue. (There is a underscore before mount)

from google.colab import drive
drive._mount('/content/drive')
Blue
  • 385
  • 3
  • 11
  • thanks, works for me. My code is: `drive._mount('/content/gdrive',force_remount=True)` – 0xDEADBEEF Dec 13 '21 at 10:17
  • it worked for me until today, Got "ValueError: mount failed: invalid oauth code", any idea what to do? – kawingkelvin Jan 21 '22 at 20:40
  • This is not working anymore as google has removed this feature. https://github.com/googlecolab/colabtools/issues/2562#issuecomment-1017869732 – Blue Jan 24 '22 at 07:38
3

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') 
Kyu
  • 264
  • 1
  • 4
2

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! ^^

igor
  • 21
  • 1
1

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.

DataPlug
  • 340
  • 3
  • 10
  • 1
    Yes it seems so. But not all Pro accounts are affected. The link is still given to my colleague.. – Tim Nov 08 '21 at 20:45
  • @Tim quite frustrating. Is there a way around this for Pro accounts? – DataPlug Nov 08 '21 at 20:56
  • 2
    Yes, it works if I share the required folder for my Colab Drive account and so i can access the folder from the other account via my Colab Google Drive account. But I still didn't manage to get the link back. – Tim Nov 09 '21 at 09:26
1

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