当前位置: 首页>>代码示例>>Python>>正文


Python Log.error方法代码示例

本文整理汇总了Python中config.Log.error方法的典型用法代码示例。如果您正苦于以下问题:Python Log.error方法的具体用法?Python Log.error怎么用?Python Log.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在config.Log的用法示例。


在下文中一共展示了Log.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_file

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
    def send_file(self, user_id, file_path):
        """
        @brief      send file
        @param      user_id  String
        @param      file_path  String
        @return     Bool: whether operation succeed
        """
        title = file_path.split('/')[-1]
        data = {
            'appid': Constant.API_WXAPPID,
            'title': title,
            'totallen': '',
            'attachid': '',
            'type': self.wx_conf['APPMSGTYPE_ATTACH'],
            'fileext': title.split('.')[-1],
        }

        response = self.webwxuploadmedia(file_path)
        if response is not None:
            data['totallen'] = response['StartPos']
            data['attachid'] = response['MediaId']
        else:
            Log.error('File upload error')
        
        return self.webwxsendappmsg(user_id, data)
开发者ID:CrackerCat,项目名称:WeixinBot,代码行数:27,代码来源:wechat_apis.py

示例2: auto_reload

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
def auto_reload(mod):
    """
    @brief      reload modules
    @param      mod: the need reload modules
    """
    try:
        module = sys.modules[mod]
    except:
        Log.error(traceback.format_exc())
        return False

    filename = module.__file__
    # .pyc 修改时间不会变
    # 所以就用 .py 的修改时间
    if filename.endswith(".pyc"):
        filename = filename.replace(".pyc", ".py")
    mod_time = os.path.getmtime(filename)
    if not "loadtime" in module.__dict__:
        module.loadtime = 0

    try:
        if mod_time > module.loadtime:
            reload(module)
        else:
            return False
    except:
        Log.error(traceback.format_exc())
        return False

    module.loadtime = mod_time

    echo('[*] load \'%s\' successful.\n' % mod)
    return True
开发者ID:CrackerCat,项目名称:WeixinBot,代码行数:35,代码来源:utils.py

示例3: get

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
def get(url, api=None):
    """
    @brief      http get request
    @param      url   String
    @param      api   wechat api
    @return     http response
    """
    Log.debug('GET -> ' + url)
    request = urllib2.Request(url=url)
    request.add_header(*Constant.HTTP_HEADER_CONNECTION)
    request.add_header(*Constant.HTTP_HEADER_REFERER)
    if api in ['webwxgetvoice', 'webwxgetvideo']:
        request.add_header(*Constant.HTTP_HEADER_RANGE)

    while True:
        try:
            response = urllib2.urlopen(request, timeout=30)
            data = response.read()
            response.close()
            if api == None:
                Log.debug(data)
            return data
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            Log.error(traceback.format_exc())

        time.sleep(1)
开发者ID:CrackerCat,项目名称:WeixinBot,代码行数:30,代码来源:utils.py

示例4: post

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
def post(url, params, jsonfmt=True):
    """
    @brief      http post request
    @param      url      String
    @param      params   Dict, post params
    @param      jsonfmt  Bool, whether is json format
    @return     http response
    """
    Log.debug('POST -> '+url)
    Log.debug(params)
    if jsonfmt:
        request = urllib2.Request(url=url, data=json.dumps(params, ensure_ascii=False).encode('utf8'))
        request.add_header(*Constant.HTTP_HEADER_CONTENTTYPE)
    else:
        request = urllib2.Request(url=url, data=urllib.urlencode(params))

    while True:
        try:
            response = urllib2.urlopen(request, timeout=30)
            data = response.read()
            response.close()

            if jsonfmt:
                Log.debug(data)
                return json.loads(data, object_hook=_decode_data)
            return data
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            Log.error(traceback.format_exc())

        time.sleep(1)
开发者ID:CrackerCat,项目名称:WeixinBot,代码行数:34,代码来源:utils.py

示例5: snapshot

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
    def snapshot(self):
        """
        @brief      Save basic infos for next login.
        @return     Bool: whether operation succeed.
        """
        try:
            conf = {
                'uuid': self.uuid,
                'redirect_uri': self.redirect_uri,
                'uin': self.uin,
                'sid': self.sid,
                'skey': self.skey,
                'pass_ticket': self.pass_ticket,
                'synckey': self.synckey,
                'device_id': self.device_id,
                'last_login': time.time(),
            }
            cm = ConfigManager()
            Log.debug('save wechat config')
            cm.set_wechat_config(conf)

            # save cookie
            Log.debug('save cookie')
            if self.cookie:
                self.cookie.save(ignore_discard=True)

            # save contacts
            Log.debug('save contacts')
            self.save_contacts()
        except Exception, e:
            Log.error(traceback.format_exc())
            return False
开发者ID:CrackerCat,项目名称:WeixinBot,代码行数:34,代码来源:wechat.py

示例6: upload_method

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
def upload_method(cron_id, vpn_ip, work_path, exchange, task_type):
    try:
        run_date = datetime.datetime.now().strftime("%Y%m%d")
        # remote check
        remote_check_flag = dir_check(vpn_ip, work_path)
        local_files = get_local_files(task_type, vpn_ip, work_path)
        print local_files
        # local check
        local_check_flag, size = loacal_files_check(local_files)
        if not local_files or not remote_check_flag or not local_check_flag:
            cron_trigger(cron_id, -1, size, run_date)
            return False
        his_cron_id = cron_trigger(cron_id, 0, size, run_date)
        if his_cron_id < 0:
            return False
        file_str = " ".join(local_files)
        cmd = "rsync -avz --progress %s %[email protected]%s:%s" % (file_str, "mycapitaltrade", vpn_ip, work_path)
        print cmd
        tf_out = tempfile.NamedTemporaryFile()
        tf_out_r = open(tf_out.name, "r")
        proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=tf_out)
        while proc.poll() is None:
            multiple_listen_stdout(cron_id, his_cron_id, size, run_date, tf_out_r)
            time.sleep(0.5)
        else:
            multiple_listen_stdout(cron_id, his_cron_id, size, run_date, tf_out_r)
        tf_out_r.close()
        tf_out.close()
        return True
    except:
        Log.error("rsync log failed. %s" % traceback.format_exc())
        return False
开发者ID:colin-zhou,项目名称:reserve,代码行数:34,代码来源:upload_conf.py

示例7: get_config_strategy

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
def get_config_strategy(file_content):
    ret_list = []
    try:
        config_obj = xmltodict.parse(file_content)
        st_obj = config_obj["MyExchange"]["strategies"]["strategy"]
        if not isinstance(st_obj, list):
            st_obj = [st_obj]
        for st in st_obj:
            ret_list.append(st["@model_file"])
    except Exception, ex:
        Log.error("xml parse error! %s" % ex)
开发者ID:colin-zhou,项目名称:reserve,代码行数:13,代码来源:upload_conf.py

示例8: loacal_files_check

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
def loacal_files_check(files):
    if not files:
        return False, 0
    try:
        total_size = 0
        for tfile in files:
            total_size += os.path.getsize(tfile)
        return True, total_size
    except os.error:
        Log.error("files %s not exist or can't access" % files)
        return False, 0
开发者ID:colin-zhou,项目名称:reserve,代码行数:13,代码来源:upload_conf.py

示例9: run

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
def run(str, func, *args):
    t = time.time()
    echo(str)
    r = False
    try:
        r = func(*args)
    except:
        Log.error(traceback.format_exc())
    if r:
        totalTime = int(time.time() - t)
        echo(Constant.RUN_RESULT_SUCCESS % totalTime)
    else:
        echo(Constant.RUN_RESULT_FAIL)
        exit()
开发者ID:CrackerCat,项目名称:WeixinBot,代码行数:16,代码来源:utils.py

示例10: get_ev_files

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
def get_ev_files(vpn_ip, path):
    pre_dir = os.path.dirname(path)
    my_capital = os.path.join(pre_dir, "my_capital.config")
    cli = SSHClient()
    try:
        ret = cli.cmd(vpn_ip, "cmd.run", ["cat %s" % my_capital])
        if ret.get(vpn_ip).get("retcode") == 0:
            capital_content = ret.get(vpn_ip).get("return")
            sts = get_config_strategy(capital_content)
            print "sts: ", sts
            return strategy_map_ev(sts)
    except Exception, ex:
        traceback.print_exc()
        Log.error("get ev files error! %s" % ex)
开发者ID:colin-zhou,项目名称:reserve,代码行数:16,代码来源:upload_conf.py

示例11: recover_contacts

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
 def recover_contacts(self):
     """
     @brief      recover contacts.
     @return     Bool: whether operation succeed.
     """
     try:
         self.User = pickle_load(self.pickle_file['User'])
         self.MemberList = pickle_load(self.pickle_file['MemberList'])
         self.GroupList = pickle_load(self.pickle_file['GroupList'])
         self.GroupMemeberList = pickle_load(self.pickle_file['GroupMemeberList'])
         self.SpecialUsersList = pickle_load(self.pickle_file['SpecialUsersList'])
         return True
     except Exception, e:
         Log.error(traceback.format_exc())
开发者ID:CrackerCat,项目名称:WeixinBot,代码行数:16,代码来源:wechat.py

示例12: set_cookie

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
def set_cookie(cookie_file):
    """
    @brief      Load cookie from file
    @param      cookie_file
    @param      user_agent
    @return     cookie, LWPCookieJar
    """
    cookie = cookielib.LWPCookieJar(cookie_file)
    try:
        cookie.load(ignore_discard=True)
    except:
        Log.error(traceback.format_exc())
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
    opener.addheaders = Constant.HTTP_HEADER_USERAGENT
    urllib2.install_opener(opener)
    return cookie
开发者ID:CrackerCat,项目名称:WeixinBot,代码行数:18,代码来源:utils.py

示例13: insertmany

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
    def insertmany(self, table, values):
        """
        @brief      Insert many rows in table
        @param      table  String
        @param      values  Array of tuple
        """
        c = self.conn.cursor()
        self.lock.acquire()
        n = len(values[0])
        sql = ("INSERT INTO %s VALUES (" + ",".join(['?'] * n) + ");") % table
        Log.debug('DB -> %s' % sql)

        try:
            c.executemany(sql, values)
        except Exception, e:
            Log.error(traceback.format_exc())
开发者ID:CrackerCat,项目名称:WeixinBot,代码行数:18,代码来源:sqlite_db.py

示例14: execute

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
    def execute(self, sql, value=None):
        """
        @brief      execute sql commands, return result if it has
        @param      sql  String
        @param      value  Tuple
        @return     result  Array
        """
        c = self.conn.cursor()
        self.lock.acquire()
        hasReturn = sql.lstrip().upper().startswith("SELECT")

        try:
            if value:
                c.execute(sql, value)
            else:
                c.execute(sql)

            if hasReturn:
                result = c.fetchall()
        except Exception, e:
            Log.error(traceback.format_exc())
开发者ID:CrackerCat,项目名称:WeixinBot,代码行数:23,代码来源:sqlite_db.py

示例15: mass_send

# 需要导入模块: from config import Log [as 别名]
# 或者: from config.Log import error [as 别名]
def mass_send(method, data, func):
    j = {'ret': -1, 'unsend_list':[]}
    if method == 'POST' and data:
        to_list = data['to_list']
        msg = data['msg']
        media_type = data.get('media_type', '')

        if media_type in ['img', 'emot']:
            file_path = os.path.join(app.config['UPLOAD_FOLDER'], msg)
            response = wechat.webwxuploadmedia(file_path)
            if response is not None:
                msg = response['MediaId']
        elif media_type == 'file':
            file_path = os.path.join(app.config['UPLOAD_FOLDER'], msg)
            data = {
                'appid': Constant.API_WXAPPID,
                'title': msg,
                'totallen': '',
                'attachid': '',
                'type': wechat.wx_conf['APPMSGTYPE_ATTACH'],
                'fileext': msg.split('.')[-1],
            }
            response = wechat.webwxuploadmedia(file_path)
            if response is not None:
                data['totallen'] = response['StartPos']
                data['attachid'] = response['MediaId']
            else:
                Log.error('File upload error')
            msg = data

        for groups in split_array(to_list, 20):
            for g in groups:
                r = func(g, msg)
                if not r:
                    j['unsend_list'].append(g)
            time.sleep(1)

        j['ret'] = len(j['unsend_list'])

    return j
开发者ID:Jolly23,项目名称:WeixinBot,代码行数:42,代码来源:weixin_bot.py


注:本文中的config.Log.error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。