问题在于,每次我在Google云端中部署我的应用程序时,都会抛出一个错误以阻止部署。我正在尝试找出错误并说AttributeError: 'Blueprint' object has no attribute 'teardown_appcontext'
。我试图找到一个解决这个问题的方法,也许有人也遇到了这个问题,但是我的独特之处是没人遇到过这个问题。但是它可以在本地主机上工作。
这是错误:
Updating service [default] (this may take several minutes)...failed.
ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
[2019-11-14 16:14:41 +0000] [1] [INFO] Starting gunicorn 20.0.0
[2019-11-14 16:14:41 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2019-11-14 16:14:41 +0000] [1] [INFO] Using worker: sync
[2019-11-14 16:14:41 +0000] [9] [INFO] Booting worker with pid: 9
[2019-11-14 16:14:42 +0000] [9] [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 133, in init_process
self.load_wsgi()
File "/env/lib/python3.6/site-packages/gunicorn/workers/base.py", line 142, 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 49, in load
return self.load_wsgiapp()
File "/env/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
return util.import_app(self.app_uri)
File "/env/lib/python3.6/site-packages/gunicorn/util.py", line 331, in import_app
mod = importlib.import_module(module)
File "/env/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/vmagent/app/main.py", line 89, in <module>
from blueprints import *
File "/home/vmagent/app/blueprints/__init__.py", line 5, in <module>
from blueprints.routes.defaults.index import default_route
File "/home/vmagent/app/blueprints/routes/defaults/index.py", line 6, in <module>
minify(default_route)
File "/env/lib/python3.6/site-packages/flask_minify/main.py", line 64, in __init__
app and self.init_app(app)
File "/env/lib/python3.6/site-packages/flask_minify/main.py", line 87, in init_app
app.teardown_appcontext(self.teardown)
AttributeError: 'Blueprint' object has no attribute 'teardown_appcontext'
[2019-11-14 16:14:42 +0000] [9] [INFO] Worker exiting (pid: 9)
[2019-11-14 16:14:42 +0000] [1] [INFO] Shutting down: Master
[2019-11-14 16:14:42 +0000] [1] [INFO] Reason: Worker failed to boot.
这是main.py文件:
#!/home/kimdev/Documents/pythonwebapp/flask_v1/bin/python3
import os
import yaml
import datetime
from flask import Flask, session, make_response, request, url_for, redirect
from flask_mysqldb import MySQL
from functools import wraps
def _directory():
return os.path.dirname(os.path.abspath(__file__))
def _file(fileTarget):
return os.path.join(_directory(), fileTarget)
def isFileExists(fileTarget):
return os.path.exists(_file(fileTarget))
def cookieCheckActive(f):
@wraps(f)
def wrapper(*args, **kwargs):
_active = request.cookies.get('_active', '')
_u = request.cookies.get('_u', '')
if _active != '' and _active == '1' and 'login' not in session:
session['login'] = '1'
session['userID'] = _u
return redirect(url_for('business_dashboard.dashboard'))
else:
return f(*args, **kwargs)
return wrapper
def ifLogin(f):
@wraps(f)
def wrapper(*args, **kwargs):
if 'login' in session and session['login'] == '1':
return redirect(url_for('business_dashboard.dashboard'))
else:
return f(*args, **kwargs)
return wrapper
def ifNotLogin(f):
@wraps(f)
def wrapper(*args, **kwargs):
cookieUserID = request.cookies.get('_u', '') if '_u' in request.cookies else None
if 'login' not in session:
return redirect(url_for('business_login.login'))
# elif cookieUserID == None:
# '''
# I'm so confuse with this block of code; cause if i will not
# remember my session eventhough it must equals to NONE it return
# to true and store the cookie but when i reverse it, then the trouble
# comes in when you are logging in.
# '''
# if cookieUserID != session['userID']:
# session.clear()
#
# today = datetime.datetime.now()
# expires = datetime.timedelta(days=1)
# expires = today - expires
#
# response = make_response(redirect(url_for('business_login.login')))
#
# response.set_cookie('_u', '', expires = expires)
# response.set_cookie('_active', '', expires = expires)
#
# return response
else:
return f(*args, **kwargs)
return wrapper
app = Flask(__name__)
app.secret_key = b'\x0c\xcd\xc4\x95ri\xb9\xb2O\xea\xd9\xea\x87&*\xb3'
_dbconfig = yaml.load(open(_file('config/dbconnection.yaml')), Loader = yaml.FullLoader)
app.config['MYSQL_HOST'] = _dbconfig['DB_HOST']
app.config['MYSQL_USER'] = _dbconfig['DB_USERNAME']
app.config['MYSQL_PASSWORD'] = _dbconfig['DB_PASSWORD']
app.config['MYSQL_DB'] = _dbconfig['DB_NAME']
app.config['MYSQL_CURSORCLASS'] = 'DictCursor'
_mysql = MySQL(app)
from blueprints import *
@app.errorhandler(404)
def page_not_found(error):
return 'page not found', 404
@app.context_processor
def inject_dateYear():
return {'dateYear': datetime.datetime.now().strftime('%Y')}
if __name__ == "__main__":
app.run(host='127.0.0.1', port=8080, debug=True)
这是我的requirements.txt文件,用于上传我的应用程序所需的所有库:
Flask==1.1.1
gunicorn==20.0.0
Werkzeug==0.15.5
flask_mysqldb
passlib
flask_wtf
PyYAML
wtforms
Flask-Minify
这是用于部署我的应用的app.yaml:
runtime: python
env: flex
runtime_config:
python_version: 3
entrypoint: gunicorn -b:$PORT main:app
答案 0 :(得分:0)
由于我看不到您的class Alert: UIAlertController {
}
let alert = Alert(title: "Title", message: nil, preferredStyle: .alert)
alert.message = "Message"
模块内部的内容,因此我无法重现与您相同的错误。但是请注意,Python3 runtime for App Engine Flexible在某些方面与您的本地环境有所不同,包括pre-installed system packages。
我的建议是,您在Docker容器中运行此应用程序以模拟您的本地环境设置,并在其工作时将Docker映像部署到Cloud Run。为此,您可以激发this tutorial的灵感。