12345678910111213141516171819202122232425262728293031323334 |
- from flask import Flask, request, jsonify, make_response
- import json
- import sys
- from classify_service import classifyer
- sys.path.append("classify_service")
- import logging
- logging.basicConfig(level=logging.DEBUG)
- app = Flask(__name__)
- @app.route('/get_category', methods=["POST"])
- def get_testcase_category():
- request_data = request.data.decode('utf-8')
- try:
- app.logger.debug(request_data)
- json_data = json.loads(request_data, strict=False)
- except:
- app.logger.debug(sys.exc_info()[0])
- return make_response(jsonify({"Bad Request"}), 400)
- result = classifyer.get_testcase_label(json_data)
- return jsonify(result)
- if __name__ == "__main__":
- handler = logging.FileHandler('./flask.log', encoding='UTF-8') # 设置日志字符集和存储路径名字
- logging_format = logging.Formatter( # 设置日志格式
- '%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s')
- handler.setFormatter(logging_format)
- app.logger.addHandler(handler)
- app.run('0.0.0.0', port=8200, debug=True)
|