【问题标题】:How can i change Google Colab script to run locally?如何更改 Google Colab 脚本以在本地运行?
【发布时间】:2020-07-29 05:45:45
【问题描述】:

我有以下在 google colab 上运行的代码。我希望能够在本地运行此代码,但我经常遇到错误。

# Auth GDrive
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

# Key
downloaded = drive.CreateFile({'id': 'id1'})

# Load Up Python Files
pyDownload = drive.CreateFile({'id': 'id2'})
pyDownload.GetContentFile('file.zip')

consumer_key = ''
username = ''
private_key = downloaded.GetContentString()

关于如何使其在本地工作的任何想法?

【问题讨论】:

    标签: python python-3.x google-colaboratory pydrive


    【解决方案1】:

    您的 sn-p 中引用的 Colab auth 模块仅适用于 Colab 后端。它无法在 Colab 环境之外运行。

    为了在本地验证 PyDrive,您需要在 Google API 控制台中创建一个 OAuth 客户端应用程序并使用生成的 API 凭据。 PyDrive 文档在这里有一些示例:

    https://pythonhosted.org/PyDrive/oauth.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-04
      • 2018-11-01
      • 2021-10-24
      • 1970-01-01
      • 2019-02-19
      • 2018-12-14
      • 2020-11-15
      • 2019-01-29
      相关资源
      最近更新 更多