6

我正在关注https://developers.google.com/storage/docs/gspythonlibrary#credentials中的示例

我通过在开发中选择创建了客户端/秘密对。控制台“创建新的客户端 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
4

3 回答 3

5

在过去的几天里,我一直在为此苦苦挣扎,结果证明是 boto 的东西,而 gspythonlibrary 已经完全过时了。

显示如何使用/验证 Google Cloud Storage 的最新示例代码在这里: https ://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/storage/api

于 2016-12-09T02:47:45.390 回答
2

您需要在.boto文件中提供客户端/密钥对,然后运行gsutil config​​.

它将创建一个刷新令牌,然后应该可以工作!

有关详细信息,请参阅https://developers.google.com/storage/docs/gspythonlibrary#credentials

于 2015-11-09T19:03:35.830 回答
0

U还可以为gsutil命令认证和gsutil cp,rm,gsutil config -a通过控制台应用程序传递到云SDK然后执行控制台应用程序

于 2018-04-28T07:41:20.703 回答