python - 如何在 Google 应用引擎上使用 gcloud?

标签 python google-app-engine protocol-buffers gcloud-python google-cloud-python

我正在尝试在 Google 应用引擎上使用客户端和 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)

当我打开地址(localhost:8080/back/printstr)时,我应该在页面上看到“YA”。但我收到 HTTP ERROR 500。并且我看到了日志:

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

我确定在google(文件夹)有一个protobuf(文件夹),并且在protobuf(文件夹)有一个timestamp_pb2.py。但是,我不知道为什么会出现此错误?有关如何使用 gcloud 的任何帮助吗?

谢谢!

最佳答案

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

使用点: pip install GoogleAppEngineCloudStorageClient -t your_app_directory/lib

使用 git: 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()

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

关于python - 如何在 Google 应用引擎上使用 gcloud?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37522493/

相关文章:

python - 从 django 模型传递对象的 ID

python - panda python groupby 取决于其他列表

python - 我的 Django if 语句无法正常工作

python - 类型错误 : not enough arguments for format string in python

google-app-engine - 启用计费的 Google App Engine 应用的 OverQuotaException

java - gradle生成protobuf类但显示编译错误

python - 从 Google Cloud Endpoints 中的请求路径获取参数

java - App Engine Java - 当前使用联合登录/Openid - 我应该如何保留成功通过身份验证的 Facebook 用户?

android - Protobuf可以和NanoPB通信吗

macos - 构建@com_google_protobuf 时缺少依赖项//:protobuf_lite