Reputation: 51
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!
Upvotes: 1
Views: 505
Reputation: 888
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 clone https://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.
Upvotes: 1