【问题标题】:How to use gcloud on google app engine?如何在谷歌应用引擎上使用 gcloud?
【发布时间】:2016-05-30 09:44:36
【问题描述】:

我正在尝试在谷歌应用引擎上使用客户端和 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 的任何帮助?

谢谢!

【问题讨论】:

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


    【解决方案1】:

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

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

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

    确保您的应用引擎可以访问您的云存储桶。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-01
      • 1970-01-01
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      相关资源
      最近更新 更多