You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Google Colab Enterprise挂载驱动器遇客户端ID/密钥错误求解决

Google Colab Enterprise挂载Google Drive时"需指定client id和secret"错误的解决方法

问题描述

在Google Colab Enterprise中执行以下挂载命令:

!sudo echo -ne '
' | sudo add-apt-repository ppa:alessandro-strada/ppa >/dev/null 2>&1 # 抑制输出
!sudo apt update >/dev/null 2>&1
!sudo apt install google-drive-ocamlfuse >/dev/null 2>&1
!google-drive-ocamlfuse
!sudo apt-get install w3m >/dev/null 2>&1 # 用作网页浏览器
!xdg-settings set default-web-browser w3m.desktop >/dev/null 2>&1 # 设置默认浏览器
%cd /content
!mkdir gdrive
%cd gdrive
!mkdir "My Drive"
!google-drive-ocamlfuse "/content/gdrive/My Drive"

执行后触发错误:

You should specify a client id (-id) and a client secret (-secret)

解决方法

方法一:配置OAuth凭据适配google-drive-ocamlfuse

  1. 创建并配置Google Cloud项目

    • 打开Google Cloud控制台,新建或选择现有项目
    • 在API和服务页面,搜索并启用「Google Drive API」
  2. 生成OAuth客户端ID和密钥

    • 进入API和服务的「凭据」页面,点击「创建凭据」→「OAuth客户端ID」
    • 应用类型选择「桌面应用」,填写名称后完成创建
    • 保存生成的客户端ID和客户端密钥
  3. 在Colab中完成授权配置
    将原命令中的!google-drive-ocamlfuse替换为以下命令(替换占位符为你的凭据):

    !google-drive-ocamlfuse -id "你的客户端ID" -secret "你的客户端密钥"
    

    执行后会输出授权链接,复制链接到浏览器打开,完成账号授权后,将页面返回的授权码粘贴回Colab终端。

  4. 重新执行挂载命令
    授权完成后,继续执行目录创建和挂载操作:

    %cd /content
    !mkdir -p gdrive/"My Drive"
    !google-drive-ocamlfuse "/content/gdrive/My Drive"
    

方法二:使用Colab官方原生挂载方式(更简便)

Colab Enterprise提供了官方内置的挂载工具,无需配置第三方工具,直接执行以下代码即可:

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

执行后点击弹出的授权链接,完成验证后即可完成挂载,稳定性更高。

内容的提问来源于stack exchange,提问作者Jyoti yadav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 22:24:56