请问用python的telnetlib进行telnet登录时,连接上去又被ACL拒了然后代码报错。请问该如何处理这个异常,结束这次登陆尝试?
try:
self.tn = telnetlib.Telnet(host_ip,port=23,timeout=2)
except:
logging.warning("failed to connect to host:%s" %host_ip)
return False
self.tn.read_until(b'Username:', timeout=3)
self.tn.write(user_name.encode('ascii') + b'
')
self.tn.read_until(b'Password:', timeout=3)
self.tn.write(pass_word.encode('ascii') + b'
')
手动登录测试:
![image image](https://cdn.ostack.cn/v-5feb05cf/global/img/squares.svg)
代码报错:
![image image](https://cdn.ostack.cn/v-5feb05cf/global/img/squares.svg)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…