1

我正试图在谷歌应用引擎上使用客户端和gcloud桶。 首先,我安装gcloud。如何在谷歌应用引擎上使用gcloud?

pip install gcloud -t my_project_directory 

其次,我开始导入gcloud并使用它。这里是我的代码:

from gcloud import storage 

class printstr(webapp2.RequestHandler): 
    def get(self): 
     self.response.out.write("YA") 

config = {} 
config['webapp2_extras.sessions'] = { 
'secret_key': 'my-super-secret-key', 
} 

app = webapp2.WSGIApplication([('/back/printstr', printstr), 
          ], debug=True, config=config) 

当我打开地址(本地主机:8080 /后退/ printstr),我应该看到 “YA” 的页面上。但我得到的HTTP错误500,我看到日志:

from google.protobuf import timestamp_pb2 
ImportError: No module named protobuf 

我敢肯定有在谷歌(文件夹)一个protobuf的(文件夹),并有一个timestamp_pb2.py在protobuf的(文件夹)。但是,我不知道为什么我会得到这个错误?我应该如何使用gcloud?

谢谢!

回答

1

有一个更好的方法来做到这一点。您可以使用cloudstorage python client api将您的应用引擎与您的云存储桶连接起来。

使用PIP: PIP安装GoogleAppEngineCloudStorageClient -t your_app_directory/lib目录

使用Git: 混帐克隆https://github.com/GoogleCloudPlatform/appengine-gcs-client.git

一旦你有了这个库在你的Python路径运行:

import cloudstorage as gcs 

path = "/<bucket_name>/<file_path>" 
gcs_file = gcs.open(path) 
data = gcs_file.read() 
gcs_file.close() 

确保您的应用引擎具有访问权限s到您的云存储桶。