Google 云存储客户端

Google Cloud Storage Client

我开始使用 GCS

首先,我在我的项目中创建了服务帐户,并在 json

中获取了密钥文件

接下来,我试着写这样的脚本sample

但是...

from gcloud import storage

client = storage.Client.from_service_account_json('/path/to/keyfile.json')

bucket = client.get_bucket('enggeo')
# Then do other things...
blob = bucket.get_blob('/ETicket.pdf')
print blob.download_as_string()
blob2 = bucket.blob('/wtt.txt')
blob2.upload_from_filename(filename='/home/test2/.www/test')

出现错误

File "tt.py", line 3, in <module>
client = storage.Client.from_service_account_json('/path/to/keyfile.json')  # TODO: rel paths
File "/home/test2/lib/python2.7/site-packages/gcloud/client.py", line 64, in from_service_account_json
return cls(*args, **kwargs)
File "/home/test2/lib/python2.7/site-packages/gcloud/storage/client.py", line 53, in __init__
http=http)
File "/home/test2/lib/python2.7/site-packages/gcloud/client.py", line 181, in __init__
_ClientProjectMixin.__init__(self, project=project)
File "/home/test2/lib/python2.7/site-packages/gcloud/client.py", line 146, in __init__
raise ValueError('Project was not passed and could not be '

项目未通过,无法从环境判断。

怎么了?

client = storage.Client.from_service_account_json('/path/to/keyfile.json', 'project')

需要为 JSONClient 指定参数

https://googlecloudplatform.github.io/gcloud-python/stable/gcloud-api.html#gcloud.client.JSONClient