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到您的雲存儲桶。