Exemplo n.º 1
0
async def population(
    token: APIKey = Depends(get_api_key),
    db: Session = Depends(get_db),
    country_filters: RegionFilters = Depends(get_allow_empty_region_filters),
) -> PopulationInResponse:
    """
    查询人口数据信息 <br/>
    region: 国家 (非必传,默认值查全部国家) <br/>
    """

    logger.info(
        f"received parameters, token:{token}, country_filters: {country_filters}"
    )

    try:
        _population = list()
        population_data = Population.get_population(
            db=db, country=country_filters.name)
        for _d in population_data:
            _population.append(
                PopulationModel(name=_d.country_en,
                                population_num=_d.population_num))
    except Exception as e:
        logger.error(f"{SYSTEM_ERROR}: {e}")
        raise CustomException(SYSTEM_ERROR)

    return PopulationInResponse(data=_population)
Exemplo n.º 2
0
    def send_mail(self, msg, adds):
        """
        发送邮件
        :param msg: 邮件内容
        :param adds: 收件人信息
        :return: bool
        """
        receivers = adds
        message = MIMEText(msg, 'plain', 'utf-8')
        message['From'] = Header(SENDER, 'utf-8')
        message['To'] = Header("", 'utf-8')
        subject = SUBJECT
        message['Subject'] = Header(subject, 'utf-8')

        try:
            smtp = smtplib.SMTP_SSL(host=MAIL_HOST)
            smtp.connect(MAIL_HOST, MAIL_PORT)
            smtp.login(MAIL_USER, MAIL_PASS)
            smtp.sendmail(SENDER, receivers, message.as_string())
            logger.info(
                f"send email notification successfully, the recipient is: {adds}. message: {msg}"
            )
            return True
        except Exception as e:
            logger.error(f"Failed to send mail to: {adds}. error: {e}")
            return False
Exemplo n.º 3
0
def get_acct_place(lat, lng):
    # 根据node版本来,此接口失败可能性较高,得多请求几次
    params = {"key": TECENT_KEY, "location": lat + ',' + lng}
    result = requests.get(GET_ACCT_PLACE_URL, params=params)

    if json.loads(result.text).get('status') != 0:
        params['key'] = TECENT_KEY2
        result = requests.get(GET_ACCT_PLACE_URL, params=params)
        if json.loads(result.text).get('status') != 0:
            params['key'] = TECENT_KEY3
            result = requests.get(GET_ACCT_PLACE_URL, params=params)
            if json.loads(result.text).get('status') != 0:
                params['key'] = TECENT_KEY4
                result = requests.get(GET_ACCT_PLACE_URL, params=params)
                if json.loads(result.text).get('status') != 0:
                    logger.error('获取位置信息异常')
                    return resp_200_fail(resp_type='GET_ACCT_PLACE',
                                         message='获取位置信息异常')
                else:
                    return json.loads(result.text)
            else:
                return json.loads(result.text)
        else:
            return json.loads(result.text)
    else:
        return json.loads(result.text)
Exemplo n.º 4
0
async def infection_global_detail(token: APIKey = Depends(get_api_key),
                                  db: Session = Depends(get_db)
                                  ) -> InfectionGlobalDataInResponse:
    """
     查询全球疫情数据信息 <br/>
     """

    logger.info(f"received parameters, token:{token}")

    try:
        global_detail = GlobalDataModel()
        global_data = Covid19.get_infection_global_data(db=db)
        last_update_date = Covid19.get_last_update_date(db=db)
        for _d in global_data:
            global_detail.region.update({
                _d.country_en: {
                    "confirmed_add": _d.confirmed_add,
                    "deaths_add": _d.deaths_add,
                    "recovered_add": _d.recovered_add
                }
            })
            global_detail.last_update_date = str(last_update_date)
            global_detail.confirmed_add += _d.confirmed_add
            global_detail.deaths_add += _d.deaths_add
            global_detail.recovered_add += _d.recovered_add
    except Exception as e:
        logger.error(f"{SYSTEM_ERROR}: {e}")
        raise CustomException(SYSTEM_ERROR)

    return InfectionGlobalDataInResponse(data={"global": global_detail})
Exemplo n.º 5
0
def search_user_place(type: str = 'search', city_id: int = 1, keyword: str = None) -> Dict:
    """
    根据type,city_id和keyword查询最近的地点
     [{"name":"普天科创产业园","address":"上海市徐汇区宜山路700号","latitude":31.176567,"longitude":121.417537,"geohash":"31.176567,121.417537"},{"name":"上海普天工业园A区","address":"上海市奉贤区南桥环城北路999号","latitude":30.955165,"longitude":121.442938,"geohash":"30.955165,121.442938"},{"name":"上海普天科技产业基地三期","address":"上海市徐汇区 ","latitude":31.177047,"longitude":121.418087,"geohash":"31.177047,121.418087"},{"name":"上海普天工业园B区","address":"上海市奉贤区南桥环城北路1099号","latitude":30.953371,"longitude":121.440985,"geohash":"30.953371,121.440985"},{"name":"上海普天工业园","address":"上海市奉贤区沪杭公路1377号内部西南方向80米","latitude":30.953068,"longitude":121.444041,"geohash":"30.953068,121.444041"},{"name":"上海普天信息产业园B2楼","address":"上海市徐汇区田林街道宜山路700号普天信息产业园b2座","latitude":31.175891,"longitude":121.41769,"geohash":"31.175891,121.41769"},{"name":"中国普天","address":"上海市嘉定区墨玉南路888号上海国际汽车城大厦6层","latitude":31.281632,"longitude":121.165238,"geohash":"31.281632,121.165238"},{"name":"上海普天物流有限公司(浏翔公路)","address":"上海市嘉定区浏翔公路2377号","latitude":31.356752,"longitude":121.309631,"geohash":"31.356752,121.309631"},{"name":"普天信息产业园C1楼","address":"上海市徐汇区 ","latitude":31.175351,"longitude":121.418253,"geohash":"31.175351,121.418253"},{"name":"中国普天上海信息工业园区","address":"上海市奉贤区南桥环城北路168号","latitude":30.95887,"longitude":121.45285,"geohash":"30.95887,121.45285"}]
    """

    city_info = get_city_info_by_id(city_id, cities.city_info)
    # 搜索地址
    place_info = search_place(keyword=keyword, city_name=city_info['name'], type=type)
    logger.info(f"查询的位置信息为:{place_info}")
    # name: item.title,
    # address: item.address,
    # latitude: item.location.lat,
    # longitude: item.location.lng,
    # geohash: item.location.lat + ',' + item.location.lng
    if place_info.get('status') == 0:
        city_list = []
        for place in place_info['data']:
            data = {'name': place.get('title'), 'address': place.get('address'),
                    'latitude': place.get('location').get('lat'), 'longitude': place.get('location').get('lng'),
                    'geohash': ','.join([str(place.get('location').get('lat')), str(place.get('location').get('lng'))])}
            city_list.append(data)
        return city_list
    else:
        logger.error('调用腾讯API地图查询接口查询失败,请稍后再试')
        return resp_200_fail(resp_type='posi_search', message='调用腾讯API地图查询接口查询失败,请稍后再试')
Exemplo n.º 6
0
    def execute(self, request):
        # 发起接口调用请求并接收响应
        try:
            host = self.tp_conf.get(ActiveMqTestPointEnum.host.key)
            port = self.tp_conf.get(ActiveMqTestPointEnum.port.key)
            user_name = self.tp_conf.get(ActiveMqTestPointEnum.port.key)
            password = self.tp_conf.get(ActiveMqTestPointEnum.password.key)
            destination = self.tp_conf.get(
                ActiveMqTestPointEnum.destination.key)

            conn = stomp.Connection10(host_and_ports=[(host, port)])
            conn.start()
            conn.connect(username=user_name, password=password)
            conn.send(destination=destination,
                      body=json.dumps(request),
                      headers={'amq-msg-type': 'text'})
            conn.disconnect()
            logger.info('tp->active mq:消息发送成功,destination=' + destination +
                        'msg=' + json.dumps(request))
            result = {'result_value': True}
            return result, ''

        except ConnectionError as e:
            logger.error('tp->active mq:connection error:', str(e))
            raise RuntimeError('active mq测试,调用被测系统时连接异常')
        except Exception as e:
            logger.exception('tp->active mq:runtime error:', str(e))
            raise RuntimeError('active mq测试,调用被测系统时执行异常')
Exemplo n.º 7
0
async def area_list(
        token: APIKey = Depends(get_api_key),
        db: Session = Depends(get_db),
        region_filters: RegionFilters = Depends(get_region_filters),
        hmt_filters: Hmtfilters = Depends(get_hmt_filters)
) -> AreaListInResponse:
    """
    查询指定国家的疫情城市列表数据 <br/>
    region: 国家 <br/>
    include_hmt: 默认为 true,当 region 为 China 时返回包含港澳台疫情数据信息,false 为不返回
    """

    logger.info(
        f"received parameters, token:{token}, region_filters:{region_filters}, hmt_filters: {hmt_filters}"
    )

    try:
        area_data = Covid19.get_area_list(db=db,
                                          region=region_filters.name,
                                          hmt=hmt_filters.include_hmt)
        data = [_d[0] for _d in area_data if _d[0] and _d[0] != "Recovered"]
    except Exception as e:
        logger.error(f"{SYSTEM_ERROR}: {e}")
        raise CustomException(SYSTEM_ERROR)
    return AreaListInResponse(data=data)
Exemplo n.º 8
0
 def execute_refresh(self, **kwargs):
     try:
         self.driver.refresh()
         return True
     except Exception:
         logger.error('refresh error')
         return False
Exemplo n.º 9
0
 def build_request(self):
     try:
         # 获取请参
         self.req_param = {
             'ip':
             self.tp_conf.get('ip'),
             'port':
             self.tp_conf.get('port', LogSSHTestPointEnum.port.default),
             'username':
             self.tp_conf.get('username'),
             'password':
             self.tp_conf.get('password'),
             'path':
             self.tp_conf.get('path'),
             'tail_num':
             self.tp_conf.get('tail_num'),
             'regex':
             self.tp_conf.get('regex'),
             'charset':
             self.tp_conf.get('charset',
                              LogSSHTestPointEnum.charset.default)
         }
         return self.req_param
     except RuntimeError as e:
         logger.error('tp->log:get req params error', str(e))
         raise Exception('tp->log:get req params error', str(e))
Exemplo n.º 10
0
 def read_conf_ini(conf_file):
     # 读取 server conf 文件中的所有信息
     temp = ffc.conf_as_dict(conf_file, case_sensitive=True)
     if not temp[0]:
         logger.error('agbot config {conf_file} read failed!'.format(
             conf_file=AgbotConfig._conf_ini_abs_filename))
         sys.exit(0)
     return temp[1]
Exemplo n.º 11
0
 def execute_delete_all_cookies(self, **kwargs):
     try:
         # 删除所有 cookie
         self.driver.delete_all_cookies()
         return True
     except Exception:
         logger.error('delete_all_cookies error')
         return False
Exemplo n.º 12
0
 def execute_delete_cookie_named(self, **kwargs):
     exec_param = kwargs['exec_param']
     try:
         # 删除某个 cookie
         self.driver.delete_cookie(exec_param)
         return True
     except Exception:
         logger.error('delete_cookie_named error')
         return False
Exemplo n.º 13
0
 def execute_assert_attribute(self, **kwargs):
     exec_element = kwargs['exec_element']
     exec_param = kwargs['exec_param']
     try:
         if exec_param == exec_element.get_attribute:
             return True
         return False
     except Exception:
         logger.error('assert_text error')
         return False
Exemplo n.º 14
0
 def execute_switch_to_window(self, **kwargs):
     try:
         # target 指向 window 的序号 默认为1
         handle_index = 1 if not kwargs.get('target') else int(
             kwargs.get('target'))
         handles = self.driver.window_handles
         self.driver.switch_to.window(handles[handle_index])
         return True
     except Exception as _:
         logger.error('switch_to windows error')
         return False
Exemplo n.º 15
0
 def execute_assert_text(self, **kwargs):
     exec_element = kwargs['exec_element']
     exec_param = kwargs['exec_param']
     try:
         logger.info('assert_text:预测值:%s, 实际值:%s', exec_param,
                     exec_element.text)
         if exec_param == exec_element.text:
             return True
         return False
     except Exception:
         logger.error('assert_text error')
         return False
Exemplo n.º 16
0
 def execute_drag_and_drop(self, **kwargs):
     exec_element = kwargs['exec_element']
     exec_param = kwargs['exec_param']
     try:
         exec_param_list = exec_param.split(',')
         ActionChains(self.driver).drag_and_drop_by_offset(
             exec_element, int(exec_param_list[0]),
             int(exec_param_list[1])).perform()
     except UnexpectedAlertPresentException:
         logger.error('drag error')
         return False
     return True
Exemplo n.º 17
0
def get_ordered_dict(index_list, params_name_dict, tp):
    try:
        ordered_dict = collections.OrderedDict()
        # 获取请参有序字典
        for index in index_list:
            ordered_dict[params_name_dict[index]] = tp[index - 1]
    except IndexError as e:
        flag = False
        logger.error('Index Error, test_case ' + tp[0], str(e))
        return flag, None

    flag = True
    return flag, ordered_dict
Exemplo n.º 18
0
 def read_conf_json(conf_file):
     json_conf_dict = {}
     with open(conf_file, 'rt') as f:
         content = f.read()
         if len(content) > 0:
             try:
                 conf_dict = json.loads(content, encoding='utf-8')
             except:
                 logger.error(
                     'agbot config {conf_file} read failed!'.format(
                         conf_file=AgbotConfig._conf_ini_abs_filename))
                 sys.exit(0)
             json_conf_dict.update(dict(conf_dict))
     return json_conf_dict
Exemplo n.º 19
0
async def region_list(token: APIKey = Depends(get_api_key),
                      db: Session = Depends(get_db)) -> RegionListInResponse:
    """
    查询有疫情信息的国家列表 <br/>
    """

    logger.info(f"received parameters, token:{token}")

    try:
        region_data = Covid19.get_region_list(db=db)
        data = [_d[0] for _d in region_data if _d[0]]
    except Exception as e:
        logger.error(f"{SYSTEM_ERROR}: {e}")
        raise CustomException(SYSTEM_ERROR)
    return RegionListInResponse(data=data)
Exemplo n.º 20
0
    def execute(self, request):
        try:
            es_conf = {}
            # 发起接口调用请求并接收响应
            es = Es(es_conf['server_ip'], es_conf['server_port'],
                    es_conf['auth_user'], es_conf['auth_password'])

            tp_utc_time = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S')
            resp = es.search_match(
                request.get(LogESTestPointEnum.index.key),
                self.__tc_start_time, tp_utc_time, 100,
                request.get(LogESTestPointEnum.key_word.key))
            return resp, ''
        except Exception as e:
            logger.error('tp->log: execute error: {}'.format(str(e)))
            raise Exception(str(e))
Exemplo n.º 21
0
    def build_request(self):
        tc_ctx = self.vertical_context.tc_context

        try:
            # 获取请参
            self.req_param = {
                'index': self.tp_conf.get('index'),
                'key_word': self.tp_conf.get('key_word')
            }
            # 获取 tc 执行起始时间
            time_struct = time.mktime(tc_ctx.start_time.timetuple())
            self.__tc_start_time = datetime.utcfromtimestamp(
                time_struct).strftime('%Y-%m-%dT%H:%M:%S')
            return self.req_param

        except RuntimeError as e:
            logger.error('tp->log:get req params error: {}'.format(str(e)))
            raise Exception(str(e))
Exemplo n.º 22
0
    def execute_assert_as_json(self, **kwargs):
        exec_element = kwargs['exec_element']
        exec_param = kwargs['exec_param']

        # 默认 text 内容为 json 格式,将 text 读做 dict
        # 根据 param 中表达式进行断言,只断言 '=' 的场景,并且表达式以 ',' 分割
        try:
            text_dict = json.loads(exec_element.text)
            logger.info('ui 测试 assert_as_json 实际执行结果为 {}'.format(text_dict))
            for assert_expression in exec_param.split(','):
                key, expected_value = assert_expression.split('=')
                if text_dict[key] == expected_value:
                    continue
                else:
                    return False

            return True
        except Exception:
            logger.error('assert_as_json error')
            return False
Exemplo n.º 23
0
 def __is_number_str_equal(number_str, number):
     """
     判断返回报文期望值类型不相等的时候
     数字字符串是否和数字值相等
     eg: '12.04', 12.04 ==> True
     :param number_str: (string) 数字字符串
     :param number: (int, float, string) 返回报文中的数字
     :return:
     """
     try:
         if (type(number) != type(number_str)
                 and isinstance(number, (float, int))
                 and isinstance(number_str, str)):
             return True if float(number_str) == number else False
         else:
             return True if number_str == number else False
     except ValueError as ex:
         # float(number_str) 可能发生 ValueError 错误
         logger.error(str(ex))
         return False
Exemplo n.º 24
0
    def execute(self, request):
        try:
            ssh = paramiko.SSHClient()
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)
            host = self.tp_conf.get(ShellTestPointEnum.host.key)
            user_name = self.tp_conf.get(ShellTestPointEnum.user_name.key)
            password = self.tp_conf.get(ShellTestPointEnum.password.key)

            # 默认不填端口为22
            port = self.tp_conf.get(ShellTestPointEnum.port.key)
            if port is None:
                port = SSH_PORT

            ssh.connect(host, port=port, username=user_name, password=password, allow_agent=False, look_for_keys=False)

            shell_cmd = self.tp_conf.get(ShellTestPointEnum.shell_cmd.key)
            shell_file_path = self.tp_conf.get(ShellTestPointEnum.shell_file_path.key)

            # 选择shell命令或脚本路径
            if shell_cmd is not None:
                cmd = shell_cmd
            elif shell_file_path is not None:
                cmd = 'sh %s' % shell_file_path
            else:
                logger.error('tp->shell:execute error %s', 'shell命令为空')
                raise Exception('tp->shell:execute error shell命令为空')

            stdin, stdout, stderr = ssh.exec_command(cmd)
            out_info = stdout.read().decode('utf-8')
            err_info = stderr.read().decode('utf-8')
            ssh.close()
            result = {'result': True}
            if err_info:
                result = {'result': err_info}
                logger.info('tp->shell:execute failed: %s', err_info)
            logger.info('tp->shell:execute success: %s', out_info)
            return result, ''
        except Exception as e:
            logger.error('tp->shell:execute error %s', str(e))
            raise Exception('tp->shell:execute error' + str(e))
Exemplo n.º 25
0
    def build_request(self):
        tc_ctx = self.vertical_context.tc_context
        try:
            # 获取 tc 执行起始时间
            time_struct = time.mktime(tc_ctx.start_time.timetuple())
            self.__tc_start_time = datetime.utcfromtimestamp(
                time_struct).strftime('%Y-%m-%dT%H:%M:%S')

            # 请求参数
            self.req_param[ShellTestPointEnum.host.key] = self.tp_conf.get(ShellTestPointEnum.host.key)
            if self.tp_conf.get(ShellTestPointEnum.port.key) is None:
                self.req_param[ShellTestPointEnum.port.key] = SSH_PORT
            else:
                self.req_param[ShellTestPointEnum.port.key] = self.tp_conf.get(ShellTestPointEnum.port.key)

            self.req_param[ShellTestPointEnum.user_name.key] = self.tp_conf.get(ShellTestPointEnum.user_name.key)
            self.req_param[ShellTestPointEnum.password.key] = self.tp_conf.get(ShellTestPointEnum.password.key)
            self.req_param[ShellTestPointEnum.shell_cmd.key] = self.tp_conf.get(ShellTestPointEnum.shell_cmd.key)
            self.req_param[ShellTestPointEnum.shell_file_path.key] = self.tp_conf.get(ShellTestPointEnum.shell_file_path.key)
            return self.req_param

        except RuntimeError as e:
            logger.error('tp->log:get req params error %s', str(e))
            raise Exception('tp->log:get req params error' + str(e))
Exemplo n.º 26
0
 def execute(self, request):
     ssh = paramiko.SSHClient()
     try:
         ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
         ssh.connect(request.get('ip'),
                     request.get('port'),
                     username=request.get('username'),
                     password=request.get('password'))
         cmd = 'tail -{} {}'.format(request.get('tail_num'),
                                    request.get('path'))
         stdin, stdout, stderr = ssh.exec_command(cmd)
         out = stdout.read().decode()
         pattern = re.compile(request.get('regex'))
         find_result = pattern.findall(out)
         if find_result is None:
             resp = {'result_value': None}
         else:
             resp = {'result_value': find_result}
         return resp, ''
     except Exception as e:
         logger.error('tp->log:execute error, ' + str(e))
         raise Exception('tp->log:execute error, ' + str(e))
     finally:
         ssh.close()
Exemplo n.º 27
0
async def infection_region_detail(
    token: APIKey = Depends(get_api_key),
    db: Session = Depends(get_db),
    region_filters: RegionFilters = Depends(get_region_filters),
    date_filters: DateFilters = Depends(get_date_filters),
    hmt_filters: Hmtfilters = Depends(get_hmt_filters),
) -> InfectionRegionDetailInResponse:
    """
    查询指定国家在某段时间内的疫情明细数据信息 <br/>
    region: 国家 (必传,默认值为 China) <br/>
    start_date: 开始日期(非必传,不传代表获取最新数据。可单独指定,单独指定表示查询这一天一直到最新一天的的数据信息)) <br/>
    end_date: 结束日期 (非必传,不传代表获取最新数据。不可单独指定)<br/>
    include_hmt: 默认为 true,当 region 为 China 时返回包含港澳台疫情数据信息,false 为不返回<br/>
    日期最长可以查询10天
    """

    logger.info(
        f"received parameters, token:{token}, region_filters:{region_filters}, "
        f"date_filters: {date_filters}, hmt_filters:{hmt_filters}")

    # 判断日期
    date_filters = check_date_filter(date_filters)
    # 判断 htm
    hmt_filters = check_htm_filter(hmt_filters, region_filters)
    try:
        data = dict({"area": {}})
        area_data = Covid19.get_infection_country_area_data(
            db=db,
            country=region_filters.name,
            start_date=date_filters.start_date,
            end_date=date_filters.end_date,
            hmt=hmt_filters.include_hmt)
        for _d in area_data:
            if ("Recovered" == str(_d.province_en)):
                continue
            if not data.get("area").get(str(_d.province_en)):
                # 城市不存在
                data.get("area").update({
                    str(_d.province_en): {
                        str(_d.update_date): {
                            "confirmed_add": _d.confirmed_add,
                            "deaths_add": _d.deaths_add,
                            "recovered_add": _d.recovered_add,
                            "confirmed": _d.confirmed,
                            "deaths": _d.deaths,
                            "recovered": _d.recovered
                        }
                    }
                })
            else:
                # 城市已经存在
                if data.get("area").get(_d.province_en).get(str(
                        _d.update_date)):
                    # 日期已经存在
                    data["area"][str(_d.province_en)][str(
                        _d.update_date)]["confirmed_add"] += _d.confirmed_add
                    data["area"][str(_d.province_en)][str(
                        _d.update_date)]["deaths_add"] += _d.deaths_add
                    data["area"][str(_d.province_en)][str(
                        _d.update_date)]["recovered_add"] += _d.recovered_add
                    data["area"][str(_d.province_en)][str(
                        _d.update_date)]["confirmed"] += _d.confirmed
                    data["area"][str(_d.province_en)][str(
                        _d.update_date)]["deaths"] += _d.deaths
                    data["area"][str(_d.province_en)][str(
                        _d.update_date)]["recovered"] += _d.recovered
                else:
                    # 日期不存在
                    data.get("area").get(_d.province_en).update({
                        str(_d.update_date): {
                            "confirmed_add": _d.confirmed_add,
                            "deaths_add": _d.deaths_add,
                            "recovered_add": _d.recovered_add,
                            "confirmed": _d.confirmed,
                            "deaths": _d.deaths,
                            "recovered": _d.recovered
                        }
                    })

    except Exception as e:
        if isinstance(e, CustomException):
            logger.error(f"custom exception: {e}")
            raise e
        logger.error(f"{SYSTEM_ERROR}: {e}")
        raise CustomException(SYSTEM_ERROR)

    return InfectionRegionDetailInResponse(data=data)
Exemplo n.º 28
0
    def execute(self, request):
        content = request.get('content')
        # 请求地址可从数据文件中读取
        api_url = self.tp_conf.get('http_url')
        # 获取 http 请求方法名称
        method = self.tp_conf.get('http_method')
        # 发起接口调用请求并接收响应
        try:
            # 反射得到 http 的方法
            exec_func = getattr(requests, method.lower())
            # 请求超时时间
            try:
                timeout = int(self.tp_conf.get('timeout', 10))
            except Exception as _:
                timeout = 10
            timeout = min(timeout, 120)

            # 20190315 edit by jun.hu
            #  根据  conf 中的 content-type 来决定请求数据组织方式
            if self.__header.get('Content-Type') == 'application/json':
                response = exec_func(api_url,
                                     json=content,
                                     headers=self.__header,
                                     files=self.__file,
                                     timeout=timeout)
            else:
                if method.lower() == 'delete':
                    response = exec_func(api_url,
                                         headers=self.__header,
                                         timeout=timeout)
                else:
                    files = self.__file
                    response = exec_func(api_url,
                                         content,
                                         headers=self.__header,
                                         files=files,
                                         timeout=timeout)

            self.__resp_code = str(response.status_code)

            try:
                content = response.json()
                logger.info('[{}, {}, {}] tp->api load as json: {}, {}'.format(
                    self.vertical_context.task_context.task_model.id,
                    self.vertical_context.job_context.job_model.id,
                    self.vertical_context.tc_context.tc_detail.id,
                    response.status_code, content))
                return content, self.__resp_code
            except JSONDecodeError as e:
                logger.info(
                    '[{}, {}, {}] tp->api load as json error: {}, {}'.format(
                        self.vertical_context.task_context.task_model.id,
                        self.vertical_context.job_context.job_model.id,
                        self.vertical_context.tc_context.tc_detail.id,
                        response.status_code, response.text))
                pass

            try:
                content = self.__get_xml_dict(response.text)
                logger.info('[{}, {}, {}] tp->api load as xml: {}, {}'.format(
                    self.vertical_context.task_context.task_model.id,
                    self.vertical_context.job_context.job_model.id,
                    self.vertical_context.tc_context.tc_detail.id,
                    response.status_code, content))
                return content, self.__resp_code
            except Exception as e:
                logger.info(
                    '[{}, {}, {}] tp->api load as xml error: {}, {}'.format(
                        self.vertical_context.task_context.task_model.id,
                        self.vertical_context.job_context.job_model.id,
                        self.vertical_context.tc_context.tc_detail.id,
                        response.status_code, response.text))
                pass

            if isinstance(response.text, str) and self.tp_conf.get(
                    'resp_default_key', ''):
                return {
                    self.tp_conf.get('resp_default_key'): response.text
                }, self.__resp_code

            return response.text, self.__resp_code

        except RequestException as e:
            logger.error('[{}, {}, {}] tp->api连接异常'.format(
                self.vertical_context.task_context.task_model.id,
                self.vertical_context.job_context.job_model.id,
                self.vertical_context.tc_context.tc_detail.id))
            raise RuntimeError('api连接异常, {}'.format(str(e)))
        except RuntimeError as e:
            logger.exception('[{}, {}, {}] tp->api运行时异常, {}'.format(
                self.vertical_context.task_context.task_model.id,
                self.vertical_context.job_context.job_model.id,
                self.vertical_context.tc_context.tc_detail.id, str(e)))
            raise RuntimeError('api运行时异常, {}'.format(str(e)))