0

全部

我在 python 中的烧瓶应用程序上有一个 flask_rest plus 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

当我尝试使用 Postman 访问 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
4

1 回答 1

0

有一个对我有用的解决方案,尽管这样做似乎很奇怪:-改变了我的 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.
于 2017-10-11T13:23:16.677 回答