Error Handling In Python Try And Except
Error Handling In Python Try And Except |
Below is the script which we have used error handling. Watch the video for full explanation and subscribe to the channel for more such video.
import paramiko
p = paramiko.SSHClient()
cred = open("cred.csv","r")
for i in cred.readlines():
try:
line=i.strip()
ls =line.split(",")
p.set_missing_host_key_policy(paramiko.AutoAddPolicy())
p.connect("%s"%ls[0],port =22, username = "%s"%ls[1], password="%s"%ls[2])
stdin, stdout, stderr = p.exec_command("uname -a")
opt = stdout.readlines()
opt ="".join(opt)
temp=open("%s.txt"%ls[0],"w")
temp.write(opt)
temp.close()
except Exception as error:
print(error)
cred.close()
No comments:
Post a Comment