gpt4 book ai didi

python - WSGI 应用程序引发异常

转载 作者:太空宇宙 更新时间:2023-11-04 00:47:08 27 4
gpt4 key购买 nike

我在服务器中运行 Flask 应用程序代码时遇到 wsgi 异常。

这是我的 manage.py

from app import app1, db
from flask_script import Manager, Shell

from flask_migrate import Migrate, MigrateCommand
migrate = Migrate(app1, db)

manager = Manager(app1)
manager.add_command('db', MigrateCommand)


def make_shell_context():
return dict(app=app1, db=db)

manager.add_command("shell", Shell(make_context=make_shell_context))

if __name__ == '__main__':

manager.run()

和 app.py

app1 = Flask(__name__)
app1.config.from_object(config['default'])

rest_api = Api(app1)

db = SQLAlchemy(app1)

bcrypt = Bcrypt(app1)

from app import routes

Compress(app1)
assets = Environment(app1)
define_assets(assets)
cache = Cache(app1,config={'CACHE_TYPE': 'simple'})

在我本地,没有报错。我使用此 python manage.py runserver 命令运行我的应用程序。

现在,我在服务器中成功完成了这些步骤 python manage.py db initpython manage.py db migratepython manage.py db upgrade 并成功创建、更新数据库。我已经安装了 passenger 来为应用程序提供服务。

我的 passenger_wsgi.py 看起来像这样

from manage import  manager as application

现在,当我运行 passenger start --port 3003 -a '0.0.0.0' 时,它会抛出这个错误

[ 2016-08-16 07:44:15.0758 30180/7f90226f8700 age/Cor/Con/InternalUtils.cpp:112 ]: [Client 2-1] Sending 502 response: application did not send a complete response
App 30251 stderr: Traceback (most recent call last):
App 30251 stderr: File "/usr/share/passenger/helper-scripts/wsgi-loader.py", line 163, in main_loop
App 30251 stderr: socket_hijacked = self.process_request(env, input_stream, client)
App 30251 stderr: File "/usr/share/passenger/helper-scripts/wsgi-loader.py", line 297, in process_request
App 30251 stderr: result = self.app(env, start_response)
App 30251 stderr: TypeError: __call__() takes at most 2 arguments (3 given)

最佳答案

导入 Flask 应用程序作为要运行的应用程序,而不是 Flask-Script 管理器。

from app import app1 as application

Flask-Script 管理器用于在命令行上运行命令。它不是 WSGI 应用程序。您仍然可以使用它来运行其他命令,但 WSGI 服务器需要 Flask 应用程序。

关于python - WSGI 应用程序引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38974253/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com