[英]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.