def retry(self, url, retries, func, code=None): responset = self.startRequest(url=url, retries=retries) responset = responset.content.decode("utf8", "ignore") responset = json.loads(responset) webcode = jsonpath.jsonpath(responset, "$..code")[0] self.Logger.info([url, "msg %d" % webcode]) if webcode < 0 and retries < 3: if webcode == -403: print(webcode, "Need login. Wait 5 sec") time.sleep(5) Ey.RoboEasyLogin(self.key) print("Retry Login...%d " % retries) time.sleep(5) self.cookie = Ey.getCookie(self.key) func(retries=retries + 1, code=code) else: p = random.randint(5, 15) self.Logger.error( ("ErrorCode %d :Sleep %d sec ..." % (webcode, p))) time.sleep(p) func(retries=retries + 1, code=code) if retries == 3 and webcode < 0: raise ValueError("HTTPERROR OVER MAX RETRY TIME") print("SuccessCode %d " % webcode) return responset
def initAccount(): from middles.middleAssist import ssdbAssist from middles.middleWare import EasyMethod t = ssdbAssist.SshSSDB().connect() n = eval(t.get("robo:uname")) # n = ['zzm','com', 'cwf', 'fwb','llb'] # t = imredis().connection() for i in n: EasyMethod.RoboEasyLogin(i, 2)
Ice.loadSlice("../util/gmqi.ice") import GMQ sys.path.append("../") from util.gmqutil import sendMessagetoQueue import signal import json from gevent.queue import Queue, Empty import gevent.monkey gevent.monkey.patch_socket() from middles.middleAssist import logAsisst from tubes import RoboTubes from middles.middleWare import EasyMethod EasyMethod.RoboEasyLogin("Robo") QUEUE_IP = '10.0.0.6' QUEUE_PORT = 22345 READ_QUEUE_NAME = 'iMqDataSnatch_luobo_d' DATA_COLLECT_QUEUE_NAME = 'iMqIMDataCollect' IMMQ_PROXY = 'gmqObjectId:tcp -h 10.0.0.6 -p 22345' LOGGER_NAME = "RoboCrawlGetTask" lg = logAsisst.imLog(LOGGER_NAME)() def signal_handler(signal, frame): print('You pressed Ctrl+C!') ic.destroy() sys.exit(0)