AuthorizationError:无法在Google Colab中获取用户凭据

时间:2019-11-14 12:36:40

标签: python google-colaboratory gsuite

我有一个colab笔记本存储在共享的Google驱动器中。想法是与其他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都是陌生的,我不确定如何进行。欢迎任何帮助

1 个答案:

答案 0 :(得分:0)

显然,该问题与上一步有关。 执行完

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

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

enter image description here

我不是100%知道原因,但是它解决了问题。 希望对您有所帮助!