使用.boto google云存储api进行身份验证

时间:2015-05-25 14:41:01

标签: python-2.7 google-cloud-storage boto

谷歌云存储API存在问题。按照此处的设置进行操作:https://cloud.google.com/storage/docs/gsutil_install

这是我的代码,它应该只打印存储桶中的文件。这个结构与oauth2plugin的早期版本一起使用,但不能使它与新的gcs模块一起使用。

from gcs_oauth2_boto_plugin import oauth2_plugin
from os import path
import boto
from boto.s3.key import Key

uri = boto.storage_uri(mybucket,'gs')
for obj in uri.get_bucket():
    print obj.name

我收到此错误:

  File "C:\Users\Tim.Samain\Documents\Aptana Studio 3 Workspace\SVN\WW_7861_DL.py", line 37, in <module>
    for obj in uri.get_bucket():   File "C:\gsutil\gsutil\third_party\boto\boto\storage_uri.py", line 181, in get_bucket
    conn = self.connect()   File "C:\gsutil\gsutil\third_party\boto\boto\storage_uri.py", line 140, in connect
    **connection_args)   File "C:\gsutil\gsutil\third_party\boto\boto\gs\connection.py", line 47, in
__init__
    suppress_consec_slashes=suppress_consec_slashes)   File "C:\gsutil\gsutil\third_party\boto\boto\s3\connection.py", line 190, in __init__
    validate_certs=validate_certs, profile_name=profile_name)   File "C:\gsutil\gsutil\third_party\boto\boto\connection.py", line 572, in
__init__
    host, config, self.provider, self._required_auth_capability())   File "C:\gsutil\gsutil\third_party\boto\boto\auth.py", line 926, in get_auth_handler
    ready_handlers.append(handler(host, config, provider))   File "C:\gsutil\gsutil\third_party\gcs-oauth2-boto-plugin\gcs_oauth2_boto_plugin\oauth2_plugin.py", line 36, in __init__
    self.oauth2_client = oauth2_helper.OAuth2ClientFromBotoConfig(config)   File "C:\gsutil\gsutil\third_party\gcs-oauth2-boto-plugin\gcs_oauth2_boto_plugin\oauth2_helper.py", line 121, in OAuth2ClientFromBotoConfig
    'client_id for your application obtained from ' Exception: client_id for your application obtained from https://console.developers.google.com must be set in a boto config or with OAUTH2_CLIENT_ID environment variable or with gcs_oauth2_boto_plugin.SetFallbackClientIdAndSecret function.

我根据设置文档配置了.boto文件。我不知道为什么会收到这个错误。

谢谢

1 个答案:

答案 0 :(得分:3)

我最终在.boto文件中明确指定了client_id和client_secret。

此处讨论:https://cloud.google.com/storage/docs/gspythonlibrary

但这里没有提到:https://cloud.google.com/storage/docs/gsutil_install#config 讨论配置.boto文件

上面共享的代码然后按预期运行并打印存储桶中的所有文件。