Home > other >  Python - flask code can run locally, but run on gunicorn error
Python - flask code can run locally, but run on gunicorn error

Time:09-20

The from flask_sqlalchemy import SQLAlchemy
The from flask import flask
The from datetime import datetime
App=Flask (__name__)
App. Config [' SQLALCHEMY_DATABASE_URI]='mysql + pymysql://root: XXXXXXXX @ XXX: 3306/book'
App. Config [' SQLALCHEMY_TRACK_MODIFICATIONS]=False
# database operation is displayed when the original SQL statement, are generally open, because our backstage to log
App. Config [' SQLALCHEMY_ECHO]=True
The db=SQLAlchemy (app)
Class Book (the Model) :
__tablename__='book'
Id=db. The Column (db. The Integer, primary_key=True, autoincrement=True)
Title=the db. The Column (the String (50), nullable=False)
Db. Create_all ()

@ app. The route ('/')
Def index () :
Return "hello"
If __name__=="__main__ ':
App. The run (debug=True)
# db=SQLAlchemy ()

Can run locally, gunicorn run times wrong
The Exception in the worker process
Traceback (the most recent call last) :
The File "/usr/local/python3/lib/python3.7/site - packages/gunicorn/arbiter. Py", line 583, in spawn_worker
Worker. Init_process ()
The File "/usr/local/python3/lib/python3.7/site - packages/gunicorn/workers/base. Py", line 119, in init_process
Self. Load_wsgi ()
The File "/usr/local/python3/lib/python3.7/site - packages/gunicorn/workers/base. Py", line 144, in load_wsgi
Self. Wsgi=self. App. Wsgi ()
The File "/usr/local/python3/lib/python3.7/site - packages/gunicorn/app/base. Py", line 67, in wsgi
Self. Callable=self. The load ()
File "/usr/local/python3/lib/python3.7/site - packages/gunicorn/app/wsgiapp. Py", line 49, the load in
Return the self. Load_wsgiapp ()
File "/usr/local/python3/lib/python3.7/site - packages/gunicorn/app/wsgiapp. Py", 39, the line in load_wsgiapp
Return util. Import_app (self. App_uri)
The File "/usr/local/python3/lib/python3.7/site - packages/gunicorn/util. Py", line 358, in import_app
Mod=importlib. Import_module (module)
The File "/usr/local/python3/lib/python3.7 importlib/set py", line 127, in import_module
Return _bootstrap. _gcd_import (name [level:], package, level)
The File "& lt; Frozen importlib. _bootstrap & gt;" , line 1006, in _gcd_import
The File "& lt; Frozen importlib. _bootstrap & gt;" , line 983, in _find_and_load
The File "& lt; Frozen importlib. _bootstrap & gt;" , line 967, in _find_and_load_unlocked
The File "& lt; Frozen importlib. _bootstrap & gt;" , line 677, in _load_unlocked
The File "& lt; Frozen importlib. _bootstrap_external & gt;" , line 728, in exec_module
The File "& lt; Frozen importlib. _bootstrap & gt;" , line 219, in _call_with_frames_removed
The File "/opt/ding/ext py", line 15, in & lt; module>
db. Create_all ()
The File "/usr/local/python3/lib/python3.7/site - packages/flask_sqlalchemy/set py", line 1033, in create_all
Self. _execute_for_all_tables (app, bind, 'create_all')
The File "/usr/local/python3/lib/python3.7/site - packages/flask_sqlalchemy/set py", line 1025, in _execute_for_all_tables
The op (bind=self. Get_engine (app, bind), * * extra)
The File "/usr/local/python3/lib/python3.7/site - packages/flask_sqlalchemy/set py", line 956, in get_engine
Return the get_engine ()
The File "/usr/local/python3/lib/python3.7/site - packages/flask_sqlalchemy/set py", line 560, in get_engine
The options=self. Get_options (sa_url, echo)
The File "/usr/local/python3/lib/python3.7/site - packages/flask_sqlalchemy/set py", line 581, in get_options
The options. The update (self. _app. Config [' SQLALCHEMY_ENGINE_OPTIONS '])
TypeError: 'Boolean' object is not iterable

CodePudding user response:

This problem I can run locally, but on gunicorn server to run when I don't know why he always error when interacting with the database, the 'Boolean' object is not iterable
  • Related