[英]Can't Upload python script on Google Cloud Console. (Error response [13] && Error response [9])
I have been trying last day to deploy my script to Google Cloud console but without success!昨天我一直在尝试将我的脚本部署到 Google Cloud 控制台,但没有成功! Gcloud Version: Gcloud 版本:
Google Cloud SDK 204.0.0
beta 2017.09.15
bq 2.0.34
core 2018.06.04
gsutil 4.31
yaml file: 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
requirements.txt file:需求.txt文件:
Flask==0.12.2
gunicorn==19.8.1
I tried deploying with gcloud beta app deploy
and I am getting the following error:我尝试使用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.
I also have all my modules installed into a virtual env...我还将所有模块安装到虚拟环境中...
However, I also tried deploying with gcloud app deploy
and I am getting a different error -> ERROR: (gcloud.beta.app.deploy) Error Response: [13] Error while processing files.
但是,我也尝试使用gcloud app deploy
,但出现了不同的错误 -> ERROR: (gcloud.beta.app.deploy) Error Response: [13] Error while processing files.
Referring to a similar issue which is closed now ( https://github.com/GoogleCloudPlatform/getting-started-java/issues/281 ) I did this command gcloud config set app/use_deprecated_preparation True
, as the majority of people are saying that is working but for me is NOT!参考现在已关闭的类似问题( https://github.com/GoogleCloudPlatform/getting-started-java/issues/281 )我做了这个命令gcloud config set app/use_deprecated_preparation True
,因为大多数人都说正在工作,但对我来说不是!
Code snipet from my main.py来自我的 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]
You are using fairly low versions of gunicorn and Flask.您正在使用相当低版本的 gunicorn 和 Flask。 I would upgrade them accordingly ( google example ) and add firebase-admin, firebase and some other dependencies as well.我会相应地升级它们( 谷歌示例)并添加 firebase-admin、firebase 和其他一些依赖项。 Example requirements.txt:示例需求.txt:
Flask==1.1.1
gunicorn==20.0.4
moment==0.8.2
firebase==3.0.1
firebase-admin==3.2.1
google-api-python-client==1.7.11
I would recommend you put those dependencies in your requirements.txt file and only install from that file in a virtualenv.我建议你将这些依赖项放在你的 requirements.txt 文件中,并且只在 virtualenv 中从该文件安装。
pip3 install -r requirements.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.