使用 .boto 进行身份验证 google 云存储 api
Authenticating using .boto google cloud storage api
google 云存储 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
文件。只是不确定为什么会出现此错误。
谢谢
我最终在 .boto 文件中明确指定了 client_id 和 client_secret。
此处讨论:https://cloud.google.com/storage/docs/gspythonlibrary
但这里没有提到:https://cloud.google.com/storage/docs/gsutil_install#config
其中讨论了配置 .boto 文件
上面共享的代码然后按预期运行并打印存储桶中的所有文件。
google 云存储 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
文件。只是不确定为什么会出现此错误。
谢谢
我最终在 .boto 文件中明确指定了 client_id 和 client_secret。
此处讨论:https://cloud.google.com/storage/docs/gspythonlibrary
但这里没有提到:https://cloud.google.com/storage/docs/gsutil_install#config 其中讨论了配置 .boto 文件
上面共享的代码然后按预期运行并打印存储桶中的所有文件。