本文整理汇总了Python中paramiko.ssh_exception.AuthenticationException方法的典型用法代码示例。如果您正苦于以下问题:Python ssh_exception.AuthenticationException方法的具体用法?Python ssh_exception.AuthenticationException怎么用?Python ssh_exception.AuthenticationException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paramiko.ssh_exception
的用法示例。
在下文中一共展示了ssh_exception.AuthenticationException方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _connect
# 需要导入模块: from paramiko import ssh_exception [as 别名]
# 或者: from paramiko.ssh_exception import AuthenticationException [as 别名]
def _connect(hostname, username, passwd, timeout, port=22):
"""
get connect
:param hostname:
:param username:
:param passwd:
:param timeout:
:param port:
:return:
"""
client = None
try:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname, port, username, passwd, timeout=timeout)
except ssh_exception.NoValidConnectionsError as e:
print("username not exists")
except ssh_exception.AuthenticationException as e:
print("passwd not correct")
except Exception as e:
print("*** Caught exception: %s: %s" % (e.__class__, e))
traceback.print_exc()
return client
示例2: _sftp_connect
# 需要导入模块: from paramiko import ssh_exception [as 别名]
# 或者: from paramiko.ssh_exception import AuthenticationException [as 别名]
def _sftp_connect(hostname, username, passwd, timeout, port=22):
"""
get sftp connect
:param hostname:
:param username:
:param passwd:
:param timeout:
:param port:
:return:
"""
client = None
sftp = None
try:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname, port, username, passwd, timeout=timeout)
sftp = paramiko.SFTPClient.from_transport(client.get_transport())
except ssh_exception.NoValidConnectionsError as e:
print("username not exists")
except ssh_exception.AuthenticationException as e:
print("passwd not correct")
except Exception as e:
print("*** Caught exception: %s: %s" % (e.__class__, e))
traceback.print_exc()
return client, sftp
示例3: ssh_signup
# 需要导入模块: from paramiko import ssh_exception [as 别名]
# 或者: from paramiko.ssh_exception import AuthenticationException [as 别名]
def ssh_signup(user):
# TODO: configure nodes used for authentication
auth_node = next(iter(SSH.AVAILABLE_NODES))
ssh_key = TensorHiveManager().dedicated_ssh_key
test_client = SSHClient()
test_client.load_system_host_keys()
test_client.set_missing_host_key_policy(WarningPolicy())
try:
test_client.connect(auth_node, username=user['username'], pkey=ssh_key)
except AuthenticationException:
return {'msg': G['unpriviliged']}, 403
except (BadHostKeyException, SSHException, socket.error) as e:
return 'An error ocurred while authenticating: {}'.format(e), 500
finally:
test_client.close()
return do_create(user)
示例4: progress
# 需要导入模块: from paramiko import ssh_exception [as 别名]
# 或者: from paramiko.ssh_exception import AuthenticationException [as 别名]
def progress(args):
"""print progress of requested seqc run(s) to less
:param args: namespace object from argparse, must include rsa-key and instance-id
:return None:
"""
if args.rsa_key is None:
raise ValueError('User must supply -k/--rsa-key or set the environment variable '
'AWS_RSA_KEY')
if args.instance_ids is None:
raise ValueError('No instances specified. Please supply an instance using the -i '
'parameter.')
for id_ in args.instance_ids:
connection = ec2.SSHConnection(id_, args.rsa_key)
try:
out, err = connection.execute('cat ./seqc_log.txt')
except AuthenticationException:
raise ValueError('instance %s cannot be found.' % repr(id_))
except ClientError:
raise ValueError('instance %s cannot be found.' % repr(id_))
p = Popen(['less'], stdin=PIPE)
p.communicate(input='\n'.join(out).encode())
示例5: create_conn_obj
# 需要导入模块: from paramiko import ssh_exception [as 别名]
# 或者: from paramiko.ssh_exception import AuthenticationException [as 别名]
def create_conn_obj(self):
self.conn = paramiko.SSHClient()
self.conn.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
self.conn.connect(self.host, port=self.args.port)
except AuthenticationException:
return True
except SSHException:
return True
except NoValidConnectionsError:
return False
except socket.error:
return False
示例6: run
# 需要导入模块: from paramiko import ssh_exception [as 别名]
# 或者: from paramiko.ssh_exception import AuthenticationException [as 别名]
def run(self):
try:
(r, addr) = self.get_connection()
# Found that r should be either a socket from the socket library or None
self.__inr = r
self.__addr = addr # This should be an IP address as a string? or None
self._agent.connect()
if not isinstance(self._agent, int) and (self._agent._conn is None or not hasattr(self._agent._conn, 'fileno')):
raise AuthenticationException("Unable to connect to SSH agent")
self._communicate()
except:
#XXX Not sure what to do here ... raise or pass ?
raise
示例7: exec_command_over_ssh
# 需要导入模块: from paramiko import ssh_exception [as 别名]
# 或者: from paramiko.ssh_exception import AuthenticationException [as 别名]
def exec_command_over_ssh(self,
command: str = 'ifconfig',
ssh_user: str = 'root',
ssh_password: Union[None, str] = None,
ssh_pkey: Union[None, RSAKey] = None,
ssh_host: str = '192.168.0.1',
need_output: bool = True,
exit_on_failure: bool = True) -> Union[None, bool, str]:
"""
Exec cmd command over SSH
:param command: CMD command string (example: 'ifconfig')
:param ssh_user: SSH user string (example: 'root')
:param ssh_password: SSH password string or None if use ssh private key
:param ssh_pkey: SSH private key or None if use ssh password
:param ssh_host: SSH host string (example: '192.168.0.1')
:param need_output: Need command output or not (default: True)
:param exit_on_failure: Exit in case of error (default: False)
:return: True or False if not need output, Output string or None if need output
"""
command_result: Union[None, str] = None
try:
assert not (ssh_password is None and ssh_pkey is None), \
'SSH password and private key is None'
ssh_client: SSHClient = SSHClient()
ssh_client.set_missing_host_key_policy(AutoAddPolicy())
if ssh_password is not None:
ssh_client.connect(hostname=ssh_host, username=ssh_user, password=ssh_password)
if ssh_pkey is not None:
ssh_client.connect(hostname=ssh_host, username=ssh_user, pkey=ssh_pkey)
if need_output:
stdin, stdout, stderr = ssh_client.exec_command(command)
command_result = stdout.read().decode('utf-8') + stderr.read().decode('utf-8')
ssh_client.close()
return command_result
else:
ssh_client.exec_command(command)
ssh_client.close()
return True
except AssertionError as Error:
self.print_error(Error.args[0])
except NoValidConnectionsError:
self.print_error('Could not connect to SSH host: ', ssh_host)
except AuthenticationException:
self.print_error('SSH authentication error: ', ssh_user + '@' + ssh_host)
except SSHException as Error:
self.print_error('SSH Exception: ', Error.args[0])
if exit_on_failure:
exit(1)
if need_output:
return command_result
else:
return False
示例8: download_file_over_ssh
# 需要导入模块: from paramiko import ssh_exception [as 别名]
# 或者: from paramiko.ssh_exception import AuthenticationException [as 别名]
def download_file_over_ssh(self,
remote_path: str = '/tmp/test.txt',
local_path: str = 'test.txt',
ssh_user: str = 'root',
ssh_password: Union[None, str] = None,
ssh_pkey: Union[None, RSAKey] = None,
ssh_host: str = '192.168.0.1',
exit_on_failure: bool = True) -> Union[bool]:
"""
Transfer file over SSH
:param remote_path: Remote file path string
:param local_path: Local file path string
:param ssh_user: SSH user string (example: 'root')
:param ssh_password: SSH password string or None if use ssh private key
:param ssh_pkey: SSH private key or None if use ssh password
:param ssh_host: SSH host string (example: '192.168.0.1')
:param exit_on_failure: Exit in case of error (default: False)
:return: True or False if not need output, Output string or None if need output
"""
try:
assert not (ssh_password is None and ssh_pkey is None), \
'SSH password and private key is None'
ssh_client: SSHClient = SSHClient()
ssh_client.set_missing_host_key_policy(AutoAddPolicy())
if ssh_password is not None:
ssh_client.connect(hostname=ssh_host, username=ssh_user, password=ssh_password)
if ssh_pkey is not None:
ssh_client.connect(hostname=ssh_host, username=ssh_user, pkey=ssh_pkey)
sftp = ssh_client.open_sftp()
sftp.get(remote_path, local_path)
sftp.close()
ssh_client.close()
return True
except AssertionError as Error:
self.print_error(Error.args[0])
except NoValidConnectionsError:
self.print_error('Could not connect to SSH host: ', ssh_host)
except AuthenticationException:
self.print_error('SSH authentication error: ', ssh_user + '@' + ssh_host)
except SSHException as Error:
self.print_error('SSH Exception: ', Error.args[0])
except FileNotFoundError:
self.print_error('Not found remote file: ', remote_path)
if exit_on_failure:
exit(1)
return False
# endregion
# endregion