gpt4 book ai didi

python - 无法在 python 中使用 gcs 进行身份验证

转载 作者:太空狗 更新时间:2023-10-29 23:58:59 25 4
gpt4 key购买 nike

我正在按照 https://developers.google.com/storage/docs/gspythonlibrary#credentials 中的示例进行操作

我通过在开发中选择来创建客户端/ secret 对。控制台“创建新客户端 ID”、“已安装的应用程序”、“其他”。

我的 python 脚本中有以下代码:

import boto
from gcs_oauth2_boto_plugin.oauth2_helper import SetFallbackClientIdAndSecret
CLIENT_ID = 'my_client_id'
CLIENT_SECRET = 'xxxfoo'
SetFallbackClientIdAndSecret(CLIENT_ID, CLIENT_SECRET)

uri = boto.storage_uri('foobartest2014', 'gs')
header_values = {"x-goog-project-id": proj_id}
uri.create_bucket(headers=header_values)

它失败并出现以下错误:

   File "/usr/local/lib/python2.7/dist-packages/boto/storage_uri.py", line 555, in create_bucket
conn = self.connect()
File "/usr/local/lib/python2.7/dist-packages/boto/storage_uri.py", line 140, in connect
**connection_args)
File "/usr/local/lib/python2.7/dist-packages/boto/gs/connection.py", line 47, in __init__
suppress_consec_slashes=suppress_consec_slashes)
File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 190, in __init__
validate_certs=validate_certs, profile_name=profile_name)
File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 572, in __init__
host, config, self.provider, self._required_auth_capability())
File "/usr/local/lib/python2.7/dist-packages/boto/auth.py", line 883, in get_auth_handler
'Check your credentials' % (len(names), str(names)))
boto.exception.NoAuthHandlerFound: No handler was ready to authenticate. 3 handlers were checked. ['OAuth2Auth', 'OAuth2ServiceAccountAuth', 'HmacAuthV1Handler'] Check your credentials

最佳答案

过去几天我一直在为此苦苦挣扎,结果发现 boto 的东西,以及 gspythonlibrary 都完全过时了。

此处显示了如何使用/验证 Google 云存储的最新示例代码: https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/storage/api

关于python - 无法在 python 中使用 gcs 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24476822/

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