我是 Boto 和 Google Cloud Storage 的新手,正在学习本教程。
我遇到两个问题:
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,所以对我来说为什么它的行为不同是个谜。如果你有什么想法,请指教。谢谢