def execute(self): """执行业务逻辑""" logger.info( 'API REQUEST INFO[' + self.request.path + '][' + self.request.method + '][' + self.request.remote_ip + '][' + str(self.request.arguments) + ']', ApiImageClassification) img_file = self.get_argument('img_file', '') if img_file == '': return {'code': 2, 'msg': 'img_file不能为空'} res = {} try: ret, msg, res = classification_infer.infer(img_file) if ret != 0: logger.error('execute fail [' + img_file + '] ' + msg, ApiImageClassification) return {'code': 4, 'msg': '查询失败'} except: logger.error( 'execute fail [' + img_file + '] ' + logger.get_trace(), ApiImageClassification) return {'code': 5, 'msg': '查询失败'} # 组织返回格式 return {'code': 0, 'msg': 'success', 'data': res}
def post(self): """post请求处理""" try: result = self.execute() except: logger.error('execute fail ' + logger.get_trace(), ApiImageDigit) result = {'code': 1, 'msg': '查询失败'} logger.info('API RES[' + self.request.path + '][' + self.request.method + '][' + str(result['code']) + '][' + str(result['msg']) + ']', ApiImageDigit) self.write(json.dumps(result))