简体   繁体   中英

How to use gcloud on google app engine?

I'm trying to use client and buckets of gcloud on google app engine. First, I install gcloud.

pip install gcloud -t my_project_directory

Second,I start to import gcloud and use it. Here is my code:

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)

When I open the address(localhost:8080/back/printstr), I should see "YA" on the page. But I get HTTP ERROR 500. And I see the log:

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

I'm sure there is a protobuf(folder) at google(folder), and there is a timestamp_pb2.py at protobuf(folder). But, I have no idea why do I get this error? Any help on how should I use gcloud?

Thanks!

There is a better way to do that. You can use cloudstorage python client api to connect your app engine with your cloud storage buckets.

Using pip: pip install GoogleAppEngineCloudStorageClient -t your_app_directory/lib

Using git: git clonehttps://github.com/GoogleCloudPlatform/appengine-gcs-client.git

Once you have this library running in your python path:

import cloudstorage as gcs

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

Make sure that your app engine have access to your cloud storage buckets.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM