# Buggy code
def auth(self):
    raise NotImplementedError


# Traceback (TypeError)
Python 3.6.12 (default, Sep 23 2020, 11:07:23)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux
Type "help", "copyright", "credits" or "license" for more information.
from pssh.utils import enable_debug_logger
enable_debug_logger()
from pssh.clients import SSHClient
client = SSHClient(host='127.0.0.1', user='jenkins', timeout=10)
Connecting to 127.0.0.1:22
Agent auth failed with Unable to connect to agentcontinuing with other authentication methods
Trying to authenticate with identity file /fs/home/jenkins/.ssh/id_rsa
Authentication succeeded with identity file /fs/home/jenkins/.ssh/id_rsa
Private key auth failed, trying password
Agent auth failed with Unable to connect to agentcontinuing with other authentication methods
Trying to authenticate with identity file /fs/home/jenkins/.ssh/id_rsa
Authentication with identity file /fs/home/jenkins/.ssh/id_rsa failed, continuing with other identities
Trying to authenticate with identity file /fs/home/jenkins/.ssh/id_dsa
Authentication with identity file /fs/home/jenkins/.ssh/id_dsa failed, continuing with other identities
Trying to authenticate with identity file /fs/home/jenkins/.ssh/identity
Authentication with identity file /fs/home/jenkins/.ssh/identity failed, continuing with other identities
No authentication methods succeeded
Agent auth failed with Unable to connect to agentcontinuing with other authentication methods
Trying to authenticate with identity file /fs/home/jenkins/.ssh/id_rsa
Authentication with identity file /fs/home/jenkins/.ssh/id_rsa failed, continuing with other identities
Trying to authenticate with identity file /fs/home/jenkins/.ssh/id_dsa
Authentication with identity file /fs/home/jenkins/.ssh/id_dsa failed, continuing with other identities
Trying to authenticate with identity file /fs/home/jenkins/.ssh/identity
Authentication with identity file /fs/home/jenkins/.ssh/identity failed, continuing with other identities
No authentication methods succeeded
Traceback (most recent call last):
File ".../site-packages/pssh/clients/native/single.py", line 256, in _password_auth
self.session.userauth_password(self.user, self.password)
TypeError: Argument 'password' must not be None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File ".../python3.6/site-packages/pssh/clients/base/single.py", line 205, in _auth_retry
self.auth()
File ".../python3.6/site-packages/pssh/clients/native/single.py", line 246, in auth
self._password_auth()
File ".../python3.6/site-packages/pssh/clients/native/single.py", line 258, in _password_auth
raise AuthenticationError("Password authentication failed - %s", ex)
pssh.exceptions.AuthenticationError: ('Password authentication failed - %s', TypeError("Argument 'password' must not be None",))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File ".../python3.6/site-packages/pssh/clients/base/single.py", line 205, in _auth_retry
self.auth()
File ".../python3.6/site-packages/pssh/clients/native/single.py", line 240, in auth
self._identity_auth()
File ".../python3.6/site-packages/pssh/clients/base/single.py", line 312, in _identity_auth
raise AuthenticationError("No authentication methods succeeded")
pssh.exceptions.AuthenticationError: No authentication methods succeeded

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File ".../python3.6/site-packages/pssh/clients/base/single.py", line 205, in _auth_retry
self.auth()
File ".../python3.6/site-packages/pssh/clients/native/single.py", line 240, in auth
self._identity_auth()
File ".../python3.6/site-packages/pssh/clients/base/single.py", line 312, in _identity_auth
raise AuthenticationError("No authentication methods succeeded")
pssh.exceptions.AuthenticationError: No authentication methods succeeded

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../python3.6/site-packages/pssh/clients/native/single.py", line 131, in __init__
identity_auth=identity_auth)
File ".../python3.6/site-packages/pssh/clients/base/single.py", line 192, in __init__
self._init()
File ".../python3.6/site-packages/pssh/clients/base/single.py", line 197, in _init
self._auth_retry()
File ".../python3.6/site-packages/pssh/clients/base/single.py", line 209, in _auth_retry
return self._auth_retry(retries=retries+1)
File ".../python3.6/site-packages/pssh/clients/base/single.py", line 209, in _auth_retry
return self._auth_retry(retries=retries+1)
File ".../python3.6/site-packages/pssh/clients/base/single.py", line 211, in _auth_retry
raise AuthenticationError(msg, self.host, self.port, ex)
pssh.exceptions.AuthenticationError: ('Authentication error while connecting to %s:%s - %s', '127.0.0.1', 22, AuthenticationError('No authentication methods succeeded',))

# Fixed code
def auth(self):
    if self.pkey is not None:
        logger.debug("Proceeding with private key file authentication")
        return self._pkey_auth(self.pkey, password=self.password)
    if self.allow_agent:
        try:
            self._agent_auth()
        except (
            AgentAuthenticationError,
            AgentConnectionError,
            AgentGetIdentityError,
            AgentListIdentitiesError,
        ) as ex:
            logger.debug(
                "Agent auth failed with %scontinuing with other authentication methods",
                ex,
            )
        except Exception as ex:
            logger.error("Agent auth failed with - %s", ex)
        else:
            logger.debug("Authentication with SSH Agent succeeded")
            return
    if self.identity_auth:
        try:
            return self._identity_auth()
        except AuthenticationError:
            if self.password is None:
                raise
    logger.debug("Private key auth failed, trying password")
    self._password_auth()