使用paramiko ssh执行命令行设置超时问题?
import paramikoimport socket
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname='192.168.111.200', port=22, username='root', password='cainiao308')
try:
stdin, stdout, stderr = client.exec_command('df -h && sleep 3' ,timeout=2)
这里,如果不加这一行stderr.read()就捕获不到timeout异常,各位大神,有其他优雅的解决方案吗?
print(stderr.read())
print(stdout.read())
status = stdout.channel.recv_exit_status()
print(status)
except Exception as e:
if isinstance(e , socket.timeout):
print(1111111111)
print(type(e))
client.close()
以上是 使用paramiko ssh执行命令行设置超时问题? 的全部内容, 来源链接: utcz.com/a/163466.html