You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using paramiko to make SSH connections to different VMs and somehow I have got this new requirement where I will need to make a deepcopy of the paramiko SSH session.
importcopyimportparamikoclassSSH:
def__init__(self,host, username, password, port=22):
self.host=hostself.username=usernameself.password=passwordself.port=portself.ssh=Nonedef_openSSHConnection(self):
try:
print('Login to the host ({}) with credentials (username={},password={},port={})'.format(self.host,
self.username,
self.password,
self.port))
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(self.host, username=self.username, password=self.password)
self.ssh=sshifself.sshisnotNone:
print(
'Successfully in to the host ({}) with credentials (username={},password={},port={})'.format(
self.host, self.username, self.password, self.port))
else:
print('Failed to connect on host ({}) with credentials (username={},password={},port={})'.format(
self.host, self.username, self.password, self.port))
exceptExceptionase:
print(
'Failed to connect on host ({}) with credentials (username={},password={},port={})'.format(self.host,
self.username,
self.password,
self.port))
print(e)
def__enter__(self):
ifself.sshisNone:
self._openSSHConnection()
returnselfdefclose(self):
print('Exiting the SSH session from host ({})'.format(self.host))
ifself.sshisnotNone:
self.ssh.close()
self.ssh=None# def__exit__(self, exc_type, exc_val, exc_tb):
self.close()
withSSH(host='10.61.1.1',username='root',password='******') aszssh:
print(zssh)
copy_ssh=copy.deepcopy(zssh)
print(copy_ssh)
I am using paramiko to make SSH connections to different VMs and somehow I have got this new requirement where I will need to make a deepcopy of the paramiko SSH session.
The above code generates the following exception:
Environment Information:
Also tried the same script on another environment, it still throws a similar exception
The text was updated successfully, but these errors were encountered: