Python Scripting For Storage Admin Part 8 Error Handling Try And Except Method

Published: 26 February 2018
on channel: san&nasTechie
3,012
47

Support Us By Shopping Your Own Favorite Products
https://amzn.to/326qvbF
#pythonscriptingforstorageadmin #errorhandlinginpython
Python: Programming Basics for Absolute Beginners
https://amzn.to/2tS2EwV
In this script we will see how we can implement error handling in python scripting by using try and except method. Sometime is the there is an error in script or in the remote device where you are trying to connect then the script will break and stop working. Error handling using try and except method deals with these kind of situation.

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()


On this page of the site you can watch the video online Python Scripting For Storage Admin Part 8 Error Handling Try And Except Method with a duration of hours minute second in good quality, which was uploaded by the user san&nasTechie 26 February 2018, share the link with friends and acquaintances, this video has already been watched 3,012 times on youtube and it was liked by 47 viewers. Enjoy your viewing!