gpt4 book ai didi

google-cloud-platform - 使用 Colaboratory 永久允许 Google Cloud SDK 访问您的 Google 帐户

转载 作者:行者123 更新时间:2023-12-04 15:45:39 25 4
gpt4 key购买 nike

将 Google Colaboratory 与 Google Cloud 结合使用时,必须对其进行身份验证:

from google.colab import auth
auth.authenticate_user()
print('Authenticated')

运行该单元格的结果是:
Go to the following link in your browser:

https://accounts.google.com/o/oauth2/......

Enter verification code:

目前,每次启动新笔记本时,我都必须授予它访问权限并输入新密码,这让我觉得我做错了什么。

有没有办法永久允许 Google Cloud SDK 访问我的 Google 帐户?

最佳答案

您可以将凭证以 API key 的形式保存在磁盘上。这仍然需要在每个笔记本中运行一个单元来进行身份验证,但至少您不必每次都点击身份验证流程。

Getting Started with Authentication用于为服务帐户创建 API key 。

然后,在您的笔记本中,写下类似以下内容:

import os
storage_auth_info = r"""YOUR API KEY HERE"""
with open('/tmp/storage_auth_info.json', 'w') as f:
f.write(storage_auth_info)
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/tmp/storage_auth_info.json'

这将允许任何有权访问您的笔记本的人使用保存的凭据,因此请谨慎使用,例如,考虑仅授予服务帐户对您的数据的只读访问权限。

关于google-cloud-platform - 使用 Colaboratory 永久允许 Google Cloud SDK 访问您的 Google 帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55884294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com