flask上線部署————“WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.”


因為釘釘推送消息中要可以實時查看測試報告,但是釘釘只能添加報告的url,所以考慮使用flask框架搭建一個report的訪問接口,返回報告詳情。

1.接口代碼

# 訪問測試報告
from flask import Flask

app = Flask(__name__)
@app.route('/report_ikang', methods=['get'])
def index():
    page = open(file_ikang, encoding='utf-8')
    res = page.read()
    return res

@app.route('/report_tjb', methods=['get'])
def index_1():
    page = open(file_tjb, encoding='utf-8')
    res = page.read()
    return res


app.run(host='0.0.0.0', port=12345)

測試報告是使用HTMLhttprunner生成的靜態網頁,確定好路由,可以分別訪問不同的文件。

其中file_ikang、file_tjb都是指定目錄下的最新生成的文件。(點擊獲取指定目錄下的最新生成的文件)

 

但是使用以上代碼部署之后,提示如下:

 

* Serving Flask app "report_server" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.

“這個模式用於開發環境調試,部署線上需要使用WSGI替代” ......

2.查了下資料,這個提示的原因是flask需要使用WSGI啟動服務,那就是用WSGI唄

# 訪問測試報告
from flask import Flask
from gevent import pywsgi

app = Flask(__name__)
@app.route('/report', methods=['get'])
def index():
    page = open(file_ikang, encoding='utf-8')
    res = page.read()
    return res

@app.route('/report_tjb', methods=['get'])
def index_1():
    page = open(file_tjb, encoding='utf-8')
    res = page.read()
    return res

server = pywsgi.WSGIServer(('0.0.0.0', 12345), app)
server.serve_forever()

OK,問題解決。

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM