美文网首页
python的flask模块 GET与POST 与http

python的flask模块 GET与POST 与http

作者: 布口袋_天晴了 | 来源:发表于2019-06-15 10:05 被阅读0次

match_question()方法对应的http请求为:http://your_ip:your_port/matchQa?question=被抢劫了,怎么办

from app import api
from flask import request, jsonify
from app.match_qa_model import MatchQuestionAnswer

@api.route('matchQa', methods=['GET', 'POST'])
def match_question():
    try:
        data = request.get_json()
        question = data.get("question")
    except:
        question = request.args.get("question", "")
    model = MatchQuestionAnswer()
    data = model.run(question)
    return jsonify(data)

predict()方法对应的http请求为:http://your_ip:your_port/predict?sentence=我想咨询离婚的事情

@app.route('/predict', methods=['POST'])
def predict():
    try:
        sentence = request.args.get("sentence")
        app.logger.error('this is not a error')
        print(sentence)
        return utils_predict.predict(sentence,app)
    except Exception as e:
        b = bytes(str(e), encoding='utf-8')
        app.logger.error('this is a error')
        app.logger.error("Error {0}".format(str(b, encoding='utf-8')))
        return "Error {0}".format(str(b, encoding='utf-8'))

相关文章

网友评论

      本文标题:python的flask模块 GET与POST 与http

      本文链接:https://www.haomeiwen.com/subject/mcwvfctx.html