当前位置:  开发笔记 > 编程语言 > 正文

Google云端存储客户端

如何解决《Google云端存储客户端》经验,为你挑选了1个好方法。

我用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')

并得到错误

File "tt.py", line 3, in 
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 '

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

怎么了?



1> Ruslan Gali..:

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

推荐阅读
sx-March23
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有