在Google Colab中安装Google云端硬盘的永久授权 [英] Persistent authorisation for mounting Google Drive in Google Colab

查看:661
本文介绍了在Google Colab中安装Google云端硬盘的永久授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Colab,并且由于使用限制,每天至少需要重启一次笔记本.

I'm using Google Colab and need to restart my notebook at least once a day due to their usage limits.

要安装我的Google云端硬盘,请输入以下代码:

To mount my Google Drive I have the following code:

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

然后我得到提示:

在浏览器中转到以下URL: https://accounts.google. com/o/oauth2/auth?client_id = xxxxxxxxx ....

输入您的授权码:___________________________________________________

Enter your authorization code: ___________________________________________________


我如何只能授权一次并记住该授权?


How can I authorise only once and have that authorisation remembered?

理想情况下,当我登录Gmail时,授权已经生效,我只需指定要安装的云端硬盘的帐户电子邮件地址即可.

Ideally, that authorisation will have already happened as I'm signed in to Gmail and I can just specify the account email address of the Drive to mount.

但是,如果我不将auth代码存储在笔记本中的任何持久授权解决方案都很好.

However any solution of persistent authorisation where I don't store the auth code in the notebook would be great.

推荐答案

您不能将其设置为仅进行一次身份验证并以这种方式保留新的运行时,因为Colab在定期回收的VM上运行.您可以确保将force_remount设置为False,这样它就不会不必要地要求您重新授权:

You can't set it to only authenticate once and stay that way for a new runtime, because Colab runs on a VM that is recycled periodically. You can make sure force_remount is set to False so it doesn't unnecessarily ask you to reauthorize:

drive.mount('/content/gdrive', force_remount=False)

但是,每当您重置运行时时,都将需要使用其他授权码重新进行身份验证.

But any time you reset the runtime, you will need to reauthenticate with a different authorization code.

这篇关于在Google Colab中安装Google云端硬盘的永久授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆