29

我挂载到 Google 驱动器帐户 A。现在我想切换到帐户 B,但我不能这样做,因为我无法在执行时输入新的身份验证密钥drive.mount()

我尝试过但失败了:

  1. 重启浏览器,重启电脑
  2. force_remount=True在 中使用drive.mount(),它只会自动重新挂载帐户 A。不要求我提供新的挂载目标。
  3. 更改帐户密码
  4. 将运行时类型从 GPU 更改为 None 并返回到 GPU
  5. 以隐身模式打开所有内容
  6. 退出所有谷歌账户

我怎样才能:

  • 忘记以前的身份验证密钥,所以它会要求我提供一个新的?
  • 卸载驱动器并忘记以前的身份验证密钥?
4

10 回答 10

32

我发现“重新启动运行时...”不起作用,并且更改权限太麻烦了。
幸运的是,该drive模块配备了您需要的功能:

from google.colab import drive
drive.flush_and_unmount()
于 2020-01-14T23:55:02.323 回答
17

您可以通过从运行时菜单中选择“重置所有运行时...”项来重置 Colab 后端。

但是请注意,这将丢弃您当前的后端。

于 2019-02-23T04:16:04.167 回答
10

您的问题的另一个解决方案可能是终止您的会话并再次运行您的代码 ( drive.mount())。

脚步:

1)按“附加连接选项”按钮。是RAM和DISK旁边的小标志按钮吗

2)选择“管理会话”

3)按“终止”按钮

4)再次运行您的代码 ( drive.mount())。

现在将要求您放置新密钥。

于 2020-07-22T19:25:17.447 回答
10

要强制 Colab 在不等待或重置运行时的情况下请求新密钥,您可以撤销之前的密钥。去做这个:

  1. 转到https://myaccount.google.com/permissions(或手动导航到安全→在您的 Google 帐户页面上管理第三方访问),
  2. 在右上角,选择您的个人资料图片或姓名首字母,然后选择您希望其驱动器与 Colab 断开连接的帐户,
  3. Google 应用程序部分中选择Google Drive File Stream,然后选择Remove access

执行drive.mount()现在将要求一个新的密钥。

于 2019-07-12T10:14:59.763 回答
2

当您最近使用 安装和卸载时,重新安装不起作用flush_and_unmount()。您应该遵循的正确步骤是(在发布时对我有用):

安装后使用:

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

使用卸载:drive.flush_and_unmount()并且您看不到“驱动器/”文件夹,但相信我,您应该!rm -rf /content/drive在重新安装驱动器之前使用:

from google.colab import drive
drive.mount('/content/drive', force_remount=True)

您将再次收到新 Gmail 帐户的授权请求。

于 2021-05-19T06:35:10.227 回答
1

您可以在运行时终止会话 -> 管理会话。那应该可以完成工作,您可以再次重新安装驱动器。

于 2020-05-07T10:27:43.440 回答
0

重新启动运行时和删除访问权限没有帮助。我发现我使用的笔记本在挂载点上创建了目录:

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

Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).

我必须首先删除挂载点上的子目录。首先确保您的驱动器没有实际安装!

!find /content/drive

/content/drive
/content/drive/My Drive
/content/drive/My Drive/Colab Notebooks
/content/drive/My Drive/Colab Notebooks/assignment4
/content/drive/My Drive/Colab Notebooks/assignment4/output_dir
/content/drive/My Drive/Colab Notebooks/assignment4/output_dir/2020-04-05_16:17:15

上面的文件和目录是在我安装驱动器之前由笔记本意外创建的。一旦你确定(你确定吗?)你的驱动器没有安装然后删除子目录。

!rm -rf /content/drive

在此之后,我能够安装驱动器。

于 2020-04-05T16:28:52.887 回答
0

症状

  1. /content/drive 会自动安装而不安装它,也不会被要求Enter your authorization code:.
  2. 驱动器的缓存旧状态不断显示。
  3. 实际的 Google Drive 内容没有显示出来。
  4. 终止、重新启动、恢复出厂设置、撤销权限、清除 chrome 缓存不起作用。
  5. 冲洗和卸载google.colab.drive.flush_and_unmount()不起作用。

解决方案

  1. 在挂载点内创建一个虚拟文件/content/drive
  2. 花点时间确保内容 /content/driveGoogle 驱动器 UI中的内容不同。
  3. 运行rm -rf /content/drive
  4. google.colab.drive.flush_and_unmount()
  5. 从菜单Runtime -> Factory reset runtime

然后重新运行google.colab.drive.mount('/content/drive', force_remount=True)终于要求了Enter your authorization code

于 2021-07-01T03:09:33.367 回答
0

这是他们的常见问题解答中的解释。

为什么 Drive 操作有时会因配额而失败?Google Drive 实施各种限制,包括每个用户和每个文件的操作计数和带宽配额。超出这些限制将按Input/output error上述方式触发,并在 Colab UI 中显示通知。一个典型的原因是访问一个流行的共享文件,或者访问太多不同的文件太快。解决方法包括:

使用 drive.google.com 复制文件,不要广泛共享,以免其他用户用尽其限制。避免进行大量小型 I/O 读取,而是选择以存档格式(例如 .zip 或 .tar.gz 文件)将数据从 Drive 复制到 Colab VM,并在 VM 本地而不是挂载的 Drive 目录中取消存档数据. 等待一天配额限制重置。

https://research.google.com/colaboratory/faq.html#drive-quota

于 2020-09-16T07:54:09.153 回答
-1

drive.mount()函数的当前代码位于https://github.com/googlecolab/colabtools/blob/fe964e0e046c12394bae732eaaeda478bc5fa350/google/colab/drive.py

它是位于 /opt/google/drive/drive 的驱动器可执行文件的包装器。我发现可执行文件接受一个authorize_new_user可用于强制重新身份验证的标志。

将 drive.py 文件的内容复制并粘贴到您的笔记本中。然后将第 189 行的当前调用修改为d.sendline()如下所示(注意添加authorize_new_user标志):

d.sendline(
      ('cat {fifo} | head -1 | ( {d}/drive '
       '--features=max_parallel_push_task_instances:10,'
       'max_operation_batch_size:15,opendir_timeout_ms:{timeout_ms},'
       'virtual_folders:true '
       '--authorize_new_user=True '
       '--inet_family=' + inet_family + ' ' + metadata_auth_arg +
       '--preferences=trusted_root_certs_file_path:'
       '{d}/roots.pem,mount_point_path:{mnt} --console_auth 2>&1 '
       '| grep --line-buffered -E "{oauth_prompt}|{problem_and_stopped}"; '
       'echo "{drive_exited}"; ) &').format(
           d=drive_dir,
           timeout_ms=timeout_ms,
           mnt=mountpoint,
           fifo=fifo,
           oauth_prompt=oauth_prompt,
           problem_and_stopped=problem_and_stopped,
           drive_exited=drive_exited))

调用drive模块版本flush_and_unmount()或您粘贴的模块版本,然后调用您的版本mount()以其他用户身份登录!

于 2020-04-04T19:27:00.863 回答