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

2024年1月起Google Colab凭证传播失败,认证流程异常求助

解决Google Colab中"credential propagation was unsuccessful"认证问题

问题概述

自2024年1月31日起,在Chrome浏览器中运行Google Colab的Drive API认证脚本时触发错误:

MessageError: Error: credential propagation was unsuccessful

该脚本在1月25日可正常执行,但后续运行时,点击"Sign in to Colaboratory Runtimes"窗口的「Continue」按钮后,脚本直接提前终止,未等待后续的"Verify it's you"身份验证以及"Colaboratory Runtimes wants additional access to your Google Account"授权步骤,最终导致认证失败。

核心代码片段

from google.colab import auth
from google.auth import default
import gspread

auth.authenticate_user()
creds, _ = default()
gc = gspread.authorize(creds)

完整报错栈

MessageError                              Traceback (most recent call last)
<ipython-input-12-1f07d83f7bd2> in <cell line: 13>()
     11 from google.colab import auth
---&gt; 12 auth.authenticate_user()
     13
     14 import gspread

2 frames
/usr/local/lib/python3.10/dist-packages/google/colab/_message.py in read_reply_from_input(message_id, timeout_sec)
    101     ):
    102       if 'error' in reply:
--&gt; 103         raise MessageError(reply['error'])
    104       return reply.get('data', None)
    105 

MessageError: Error: credential propagation was unsuccessful

可行解决方案

1. 清除Chrome中Colab相关缓存与Cookie

  • 打开Chrome,地址栏输入chrome://settings/siteData
  • 搜索框输入google.com,选中所有与colab.research.google.com、accounts.google.com相关的条目
  • 点击「移除」后重启浏览器,重新执行脚本

2. 使用Chrome无痕模式运行Colab

  • 按下快捷键Ctrl+Shift+N打开无痕窗口,登录Google账号并打开目标Notebook
  • 重新执行认证脚本,此时完整授权流程会正常触发(包括后续身份验证和权限申请步骤)

3. 替换为服务账号密钥认证

若上述方法无效,可改用手动密钥认证绕开自动授权流程:

  1. 前往Google Cloud控制台,创建服务账号并下载JSON格式的密钥文件
  2. 在Colab中上传该密钥文件,替换原有认证代码:
import gspread
from google.oauth2.service_account import Credentials

# 定义所需权限范围
SCOPES = [
    'https://www.googleapis.com/auth/spreadsheets',
    'https://www.googleapis.com/auth/drive'
]

# 加载服务账号密钥
creds = Credentials.from_service_account_file('your-service-account-key.json', scopes=SCOPES)
gc = gspread.authorize(creds)
  1. 给服务账号授予目标Google Drive文件/表格的编辑权限

4. 检查Google账号安全设置

  • 登录Google账号安全中心,确认「两步验证」状态,若开启可临时关闭后重试
  • 检查「第三方应用访问权限」,确保Colaboratory相关权限未被限制

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 23:00:27