def _request(self, url, params): res = None retry = 0 while retry < 5: try: res = requests.post(url, data=params) break except ConnectionError as e: retry += 1 time.sleep(2) if retry == 5: runtime_logger().error("请求url:%s历史数据时出现错误:%s" % (url, e.message)) raise e return res
def req_vdata(self, user_id, compId, ak, kst_url, data): tt = int(time.time() * 10000) data['tt'] = str(tt) vprefix = Configuration().get('url_prefix', 'vprefix') pu = vprefix + '?user_id="%s"&compId="%s"' % (user_id, compId) params = { "ak": ak, "tt": str(tt), "pu": pu, "pt": "VISITORCARD", } kssign = self.gen_sign(data) params['kssign'] = kssign res = self._request(kst_url, params) result = json.loads(res.content) runtime_logger().info("用户:%s请求历史名片信息返回结果:%s" % (user_id, res.content)) conn_res = self.deal_res(result) return conn_res
def print_stack(): runtime_logger().info(traceback.format_exc().replace("\n", "####"))
import time import asyncio import pandas as pd from util.logger import print_stack, runtime_logger from util.tools import get_report_conf_info, keyword_info_fmap from core.sougousemservice import SogouSemService import warnings warnings.filterwarnings('ignore') logger = runtime_logger() class DatasourceAuth(object): @staticmethod async def do_action(userinfo): try: code, message, account_id = await SogouSemService().auth_account(userinfo) if code == "SUCCESS": return {"status":2000, "message":"OK"} else: return {"status":2100, "message":message} except Exception as e: logger.info("验证用户信息时出现错误:%s" % str(e)) print_stack() return {"status":2101, "message":str(e)} finally: logger.info("trace_id: %s auth over" % userinfo['trace_id']) class ReportService(object): @staticmethod async def get_report_data(infos, ReportRequestBag, fmap, number_list, special=False): sogou_core = SogouSemService()
def print_stack(): import traceback from util.logger import runtime_logger runtime_logger().info(traceback.format_exc().replace("\n", "####"))