Google云端存储客户端

Rus*_*mov 2 google-cloud-storage

我用GCS做了第一步

首先,我在我的项目中创建了服务帐户,并在json中获得了密钥文件

接下来,我试着像这个样本一样编写脚本

但...

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')
Run Code Online (Sandbox Code Playgroud)

并得到错误

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 '
Run Code Online (Sandbox Code Playgroud)

项目未通过,无法从环境中确定.

怎么了?

Rus*_*mov 6

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

需要为JSONClient指定args

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