В прошлый день я пытался развернуть свой скрипт в консоли Google Cloud, но безуспешно!Версия Gcloud:
Google Cloud SDK 204.0.0
beta 2017.09.15
bq 2.0.34
core 2018.06.04
gsutil 4.31
Файл yaml:
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app
runtime_config:
python_version: 3
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 1
disk_size_gb: 10
файл needs.txt:
Flask==0.12.2
gunicorn==19.8.1
Я попытался выполнить развертывание с gcloud beta app deploy
и получаюследующая ошибка:
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
[2018-06-06 09:28:47 +0000] [1] [INFO] Starting gunicorn 19.8.1
[2018-06-06 09:28:47 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2018-06-06 09:28:47 +0000] [1] [INFO] Using worker: sync
[2018-06-06 09:28:47 +0000] [7] [INFO] Booting worker with pid: 7
[2018-06-06 09:28:47 +0000] [7] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/env/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/env/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/env/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/env/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/env/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/env/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/env/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
File "/home/vmagent/app/main.py", line 5, in <module>
import firebase_admin
ModuleNotFoundError: No module named 'firebase_admin'
[2018-06-06 09:28:47 +0000] [7] [INFO] Worker exiting (pid: 7)
[2018-06-06 09:28:47 +0000] [1] [INFO] Shutting down: Master
[2018-06-06 09:28:47 +0000] [1] [INFO] Reason: Worker failed to boot.
У меня также есть все мои модули, установленные в виртуальную среду ...
Однако я также попытался выполнить развертывание с помощью gcloud app deploy
, и я получаю другую ошибку -> ERROR: (gcloud.beta.app.deploy) Error Response: [13] Error while processing files.
Обращаясь к аналогичной проблеме, которая сейчас закрыта (https://github.com/GoogleCloudPlatform/getting-started-java/issues/281) Я выполнил эту команду gcloud config set app/use_deprecated_preparation True
, так как большинство людей говорят, что работает, но для меня это НЕ!
Фрагмент кода из моего main.py
# [START app]
import logging
import sys
import firebase_admin
import moment
from datetime import datetime
from firebase_admin import credentials, db
from flask import Flask, json, make_response, render_template, request
from apiclient.discovery import build, build_from_document
from firebase import firebase
from httplib2 import Http
from oauth2client.service_account import ServiceAccountCredentials
service_account = 'FIREBASE-ADMIN-SDK-KEY'
database_url = 'FIRABE-DB-URL'
cred = credentials.Certificate(service_account)
# Initialize the app with a service account, granting admin privileges
firebase_admin.initialize_app(cred, {
'databaseURL': database_url
})
firebase = firebase.FirebaseApplication(database_url, None)
user_id = ""
rootDB = db.reference()
messagesDb = rootDB.child('messages')
app = Flask(__name__)
if sys.version_info.major < 3:
reload(sys)
sys.setdefaultencoding('utf8')
scopes = ['https://www.googleapis.com/auth/chat.bot']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'Google-Serviced-Account-KEY', scopes)
http_auth = credentials.authorize(Http())
chat = build('chat', 'v1', http=http_auth, cache_discovery=False)
# Using the rest api (send message function)
@app.route('/receiver', methods=['POST'])
def message_responses():
#Some Code here
return 'OK'
# [END message_response]
@app.route('/getMeasages', methods=['POST'])
def get_messages():
# Some Code here
return 'OK'
# [END get_messages]
@app.route('/test', methods=['POST'])
def resp_get():
event_data = request.get_json()
print(event_data)
return 'OK'
@app.route('/', methods=['GET'])
def home_get():
return render_template('home.html')
if __name__ == '__main__':
# This is used when running locally. Gunicorn is used to run the
# application on Google App Engine. See entrypoint in app.yaml.
app.run(host='localhost', port=8080, debug=True)
# [END app]