首页 > 解决方案 > AuthorizationError:无法在 google Colab 中获取用户凭据

问题描述

我有一个存储在共享谷歌驱动器中的 colab 笔记本。想法是与其他 gsuite 用户共享此笔记本。当他们将其复制粘贴到本地驱动器中时,他们中的一些人可以运行它并对其进行处理,而另一些人则打印出上述错误。

给出错误的代码如下:

!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

这部分代码打印以下错误:

AuthorizationError                        Traceback (most recent call last)
<ipython-input-9-6beb6b456bb8> in <module>()
      5 from oauth2client.client import GoogleCredentials
      6 # Authenticate and create the PyDrive client.
----> 7 auth.authenticate_user()
      8 gauth = GoogleAuth()
      9 gauth.credentials = GoogleCredentials.get_application_default()

/usr/local/lib/python3.6/dist-packages/google/colab/auth.py in authenticate_user(clear_output)
    160   if _check_adc():
    161     return
--> 162   raise _errors.AuthorizationError('Failed to fetch user credentials')

AuthorizationError: Failed to fetch user credentials

我是 colab 和 gsuite 的新手,我不知道如何继续。欢迎任何帮助

标签: pythongoogle-colaboratorygoogle-workspace

解决方案


显然这个问题与上一步有关。执行后

!pip install -U tensorflow-gpu==2.0.0 grpcio

有必要重新启动运行时,即:

在此处输入图像描述

我不是 100% 确定原因,但它解决了问题。我希望它有帮助!


推荐阅读