File tree 1 file changed +12
-8
lines changed
1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change 9
9
from loguru import logger
10
10
from retrying import retry , RetryError
11
11
import redis
12
+ from redis .exceptions import ConnectionError
12
13
13
14
if platform .python_version ().startswith ('2.' ):
14
15
import commands as subprocess
@@ -116,14 +117,17 @@ def run(self):
116
117
else :
117
118
proxy = '{ip}:{port}' .format (ip = ip , port = PROXY_PORT )
118
119
time .sleep (10 )
119
- if self .test_proxy (proxy ):
120
- logger .info (f'Valid proxy { proxy } ' )
121
- # 将代理放入数据库
122
- self .set_proxy (proxy )
123
- time .sleep (DIAL_CYCLE )
124
- else :
125
- logger .error (f'Proxy invalid { proxy } ' )
126
- else :
120
+ try :
121
+ if self .test_proxy (proxy ):
122
+ logger .info (f'Valid proxy { proxy } ' )
123
+ # 将代理放入数据库
124
+ self .set_proxy (proxy )
125
+ time .sleep (DIAL_CYCLE )
126
+ else :
127
+ logger .error (f'Proxy invalid { proxy } ' )
128
+ except ConnectionError :
129
+ logger .error ('The redis connection is abnormal' )
130
+ else :
127
131
# 获取 IP 失败,重新拨号
128
132
logger .error ('Get IP failed, re-dialing' )
129
133
self .run ()
You can’t perform that action at this time.
0 commit comments