[英]Deploying Flask_restplus Api build over Flask App using uwsgi.py on nginx server
所有
我在python的flask应用程序中有一个flask_rest加上api。 我想在nginx服务器上使用uwsgi格式部署相同的文件。 我搜索了很长时间,但没有找到写解决方案。任何线索都将有所帮助..
提前致谢。
下面是代码片段
import datetime
from fileinput import filename
import json
import os
from flask import request
from flask_restplus import Resource, Api
from werkzeug.utils import secure_filename
from APP.Application import app
from ApiConfig.ObjectConfig import Trainer, cData, Tmodal, Amodal, Cmodal
from ApiConfig.SA_utility import sentiment_sorting
from ApiConfig.appFileConfig import UPLOAD_FOLDER
from Classification.Classifier import classify
from DataBase.DB import db
from ExcelParser_DataFrame.Excel_Parser import ExcelDataFrame
from Vectorizer.Data_vector import vectorizer
from Mapper.UI_Map import UI_Map
from werkzeug.contrib.fixers import ProxyFix
api = Api(app)
app.wsgi_app = ProxyFix(app.wsgi_app)
@api.route('/sentiment-analysis/trainer')
class Upload_File(Resource):
def post(self):
..............
if __name__ == '__main__':
db.init_app(app)
db.create_all()
app.run(host='0.0.0.0')
我的wsgi.py文件看起来像这样
import sys
sys.path.insert(0, "/home/gulshan/Downloads/SA_PANDAS_SGDC/src")
from APP.Application import app
application = app
我尝试使用此wsgi文件,并通过在Linux计算机上触发以下命令来启动服务器
uwsgi --http :5000 --wsgi-file wsgi.py --callable app --processes 4 --threads 2 --stats 127.0.0.1:9191
当我尝试使用邮递员访问URL时,出现如下所示的错误:-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
我的APP.Application文件如下所示:-
from flask import Flask
from ApiConfig import Settings as settings
app = Flask(__name__)
#app.config['SERVER_NAME'] = settings.FLASK_SERVER_NAME
app.config['SQLALCHEMY_DATABASE_URI'] = settings.SQLALCHEMY_DATABASE_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = settings.SQLALCHEMY_TRACK_MODIFICATIONS
app.config['SWAGGER_UI_DOC_EXPANSION'] = settings.RESTPLUS_SWAGGER_UI_DOC_EXPANSION
app.config['RESTPLUS_VALIDATE'] = settings.RESTPLUS_VALIDATE
app.config['RESTPLUS_MASK_SWAGGER'] = settings.RESTPLUS_MASK_SWAGGER
app.config['ERROR_404_HELP'] = settings.RESTPLUS_ERROR_404_HELP
app.config['SQLALCHEMY_POOL_SIZE'] = settings.SQLALCHEMY_POOL_SIZE
#app.config['SQLALCHEMY_POOL_TIMEOUT'] = settings.SQLALCHEMY_POOL_TIMEOUT
app.config['SQLALCHEMY_POOL_RECYCLE'] = settings.SQLALCHEMY_POOL_RECYCLE
app.config['SQLALCHEMY_MAX_OVERFLOW'] = settings.SQLALCHEMY_MAX_OVERFLOW
得到了一个对我有用的解决方案,尽管这似乎是一种奇怪的方法:-更改了我的uwsgi.py
import sys
sys.path.insert(0, "/home/gulshan/Downloads/SA_PANDAS_SGDC/src")
from APP.Application import app
from flask import Flask
from SA_APP.SA import appnew
application = app
application = appnew
并将此行添加到我的第一个包含主调用的代码段文件中
api = Api(app)
appnew = app.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.