在用python进行ssh登录时提示代码错误
报错信息:
import paramiko
import time
ssh = paramiko.SSHClient()
def ssh_login(ip, port, username, passwd):
global ssh
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# ssh.connect(ip, port, username, passwd, Warning: The initial password poses security risks./n,The password needs to be changed. Change now? [Y/N]:)
ssh.connect(ip, port, username, passwd )
time.sleep(2)
# '''
conn = ssh.invoke_shell()
conn.send("n\n")
time.sleep(2)
conn.send("dis version\n")
time.sleep(2)
output = conn.recv(65535)
# time.sleep(2)
print(output.decode('utf-8'))
# ssh.close
# '''
return
def ssh_exe_cmd(cmd):
global ssh
stdin, stdout, stderr = ssh.exec_command(cmd)
str1 = stdout.read().decode('utf-8')
print(str1)
return
def main():
ssh_login('192.168.179.102', 22, 'huawei', 'Huawei@123')
# ssh_exe_cmd('dis version /r/n')
# ssh_exe_cmd('dis ip int brief')
ssh.close()
return
main()