From 5a4a82fe0a96b0b11f419ada4e8d3fa64821250f Mon Sep 17 00:00:00 2001 From: "dingyeran@163.com" Date: Tue, 31 Jan 2023 14:04:02 +0800 Subject: [PATCH] debug issue#15: https://github.com/Python3WebSpider/AdslProxy/issues/15#issue-1563696805 --- adslproxy/sender/sender.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/adslproxy/sender/sender.py b/adslproxy/sender/sender.py index afa944a..3389227 100644 --- a/adslproxy/sender/sender.py +++ b/adslproxy/sender/sender.py @@ -9,6 +9,7 @@ from loguru import logger from retrying import retry, RetryError import redis +from redis.exceptions import ConnectionError if platform.python_version().startswith('2.'): import commands as subprocess @@ -116,14 +117,17 @@ def run(self): else: proxy = '{ip}:{port}'.format(ip=ip, port=PROXY_PORT) time.sleep(10) - if self.test_proxy(proxy): - logger.info(f'Valid proxy {proxy}') - # 将代理放入数据库 - self.set_proxy(proxy) - time.sleep(DIAL_CYCLE) - else: - logger.error(f'Proxy invalid {proxy}') - else: + try: + if self.test_proxy(proxy): + logger.info(f'Valid proxy {proxy}') + # 将代理放入数据库 + self.set_proxy(proxy) + time.sleep(DIAL_CYCLE) + else: + logger.error(f'Proxy invalid {proxy}') + except ConnectionError: + logger.error('The redis connection is abnormal') + else : # 获取 IP 失败,重新拨号 logger.error('Get IP failed, re-dialing') self.run()