def handle_api_error(current_error): dbg((current_error.msg, current_error.error_no)) error_info = error.get_error_info(current_error.error_no) return make_response( jsonify({ 'code': current_error.error_no, 'msg': error_info[0] }), error_info[1])
def handle_api_error(current_error): dbg((current_error.msg, current_error.error_no)) # print_exception_info() error_info = error.get_error_info(current_error.error_no) return make_response( jsonify({ 'ret': current_error.error_no, 'msg': error_info[0] }), error_info[1])
def send_data_to_device(data, need_to_wait=True): topic = data['topic'] imei = data['imei'] send_data = bytearray([0x54, data['device_type']]) send_data += data['money'].to_bytes(4, 'big') send_data += data['duration'].to_bytes(4, 'big') send_data += data['high'].to_bytes(4, 'big') send_data += data['low'].to_bytes(4, 'big') send_data += data['pulse'].to_bytes(4, 'big') dbg(send_data) headers = {'Content-Type': 'application/json'} payload = {'code': 0, 'msg': ''} from ..tool import tools as tool try: result = tool.send_data_to_device(topic, imei, send_data, need_to_wait=need_to_wait, celery=True) if result['result'] == 0: payload['code'] = 8002 payload['msg'] = '设备正在运行' except ApiError as e: dbg((e.msg, e.error_no)) payload['code'] = e.error_no payload['msg'] = error.get_error_info(e.error_no) try: r = requests.post(data['async_url'], data=json.dumps(payload), headers=headers) dbg(r.text) except: print_exception_info() return 'ok'