soarli

Flask上线部署解除测试环境警告
前言最近发现Flask项目在运行时会报[WARNING: This is a development server...
扫描右侧二维码阅读全文
04
2022/04

Flask上线部署解除测试环境警告

AI 文章摘要
提炼中... · 本文基于 qwen2.5:14b
✨ 正在提炼文章核心脉络…

前言

最近发现Flask项目在运行时会报[WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead警告,意思是不要在生产环境使用这种方案启动程序:

image-20220404052003732

解决

使用WSGI启动服务即可解决问题(中间可能需要pip3 install gevent)

原版代码:

from paddleocr import PaddleOCR
from flask import Flask, request
import cv2
import numpy
app = Flask(__name__)

ocr = PaddleOCR(det_model_dir='./inference/small/ch_PP-OCRv2_det_infer/', rec_model_dir='./inference/small/ch_PP-OCRv2_rec_infer/',cls_model_dir='./inference/small/ch_ppocr_mobile_v2.0_cls_infer/',use_angle_cls=True,use_space_char=True, use_gpu=False)
@app.route('/xxxxxx/', methods=['get', 'POST'])
def xxxxxx():
    img_path = request.args.get("fname")
    result = ocr.ocr(img_path)
    ret = ''
    for line in result:
        ret += str(line[1][0]) + "\n"
    return str(ret)

if __name__ == '__main__':
    app.run(host='0.0.0.0')

新版代码:

from paddleocr import PaddleOCR
from flask import Flask, request
import cv2
import numpy
from gevent import pywsgi

app = Flask(__name__)

ocr = PaddleOCR(det_model_dir='./inference/small/ch_PP-OCRv2_det_infer/', rec_model_dir='./inference/small/ch_PP-OCRv2_rec_infer/',cls_model_dir='./inference/small/ch_ppocr_mobile_v2.0_cls_infer/',use_angle_cls=True,use_space_char=True, use_gpu=False)
@app.route('/xxxxxx/', methods=['get', 'POST'])
def xxxxxx():
    img_path = request.args.get("fname")
    result = ocr.ocr(img_path)
    ret = ''
    for line in result:
        ret += str(line[1][0]) + "\n"
    return str(ret)

if __name__ == '__main__':
    server = pywsgi.WSGIServer(('0.0.0.0', 5000), app)
    server.serve_forever()

解决问题!

参考资料:

https://blog.csdn.net/weixin_43642491/article/details/114916769

https://www.cnblogs.com/mlp1234/p/13743254.html

最后修改:2022 年 04 月 06 日 10 : 09 PM

👍 相关推荐

2026 年 06 月 26 日
宝塔面板部署 FastAPI + React 项目:从“从入门到放弃”到“一次点亮”的终极踩坑实录
2026 年 03 月 21 日
记一次“见鬼”的 phpStudy MySQL 闪退排查:谁偷走了我的 3306 端口?
2026 年 03 月 15 日
跨平台开发终极对决:React Native vs Flutter,2026年到底该选谁?
✂️

💬 评论

0 / 1000