我是Boto和Google Cloud Storage的新手,我正在关注此tutorial。
我遇到两个问题:
1)从命令行运行文件时
GOOGLE_STORAGE = 'gs'
# URI scheme for accessing local files.
LOCAL_FILE = 'file'
# Fallback logic. In https://console.developers.google.com
# under Credentials, create a new client ID for an installed application.
# Required only if you have not configured client ID/secret in
# the .boto file or as environment variables.
CLIENT_ID = 'your client id'
CLIENT_SECRET = 'your client secret'
gcs_oauth2_boto_plugin.SetFallbackClientIdAndSecret(CLIENT_ID, CLIENT_SECRET)
now = time.time()
CATS_BUCKET = 'cats-%d' % now
DOGS_BUCKET = 'dogs-%d' % now
# Your project ID can be found at https://console.developers.google.com/
# If there is no domain for your project, then project_id = 'YOUR_PROJECT'
project_id = 'ixxx-prod'
for name in (CATS_BUCKET, DOGS_BUCKET):
# Instantiate a BucketStorageUri object.
uri = boto.storage_uri(name, GOOGLE_STORAGE)
# Try to create the bucket.
try:
# If the default project is defined,
# you do not need the headers.
# Just call: uri.create_bucket()
header_values = {"x-goog-project-id": project_id}
uri.create_bucket(headers=header_values)
它会在create_bucket
:
oauth2client.client.AccessTokenRefreshError:invalid_grant
考虑到我的主文件夹中存在.boto
文件,我不知道如何继续。
2)另一个问题是我在PyCharm中运行相同的脚本时,它在导入gcs_oauth2_boto_plugin时崩溃。
import boto
import gcs_oauth2_boto_plugin
ImportError:无法导入名称HAS_CRYPTO
在oauth2_client.py
内有行
from oauth2client.client import HAS_CRYPTO
这个似乎抛出异常。这似乎不在命令行中发生。
命令行和PyCharm都使用相同的Virtual-env,因此对我来说,为什么它表现不同是一个谜。如果您有任何想法,请咨询。感谢
答案 0 :(得分:0)
在PyCharm(4.0.3)中它适用于我。
我唯一能想到的是重新运行:gcloud auth login