# Buggy code
def _identity_auth(self):
    for identity_file in self.IDENTITIES:
        if not os.path.isfile(identity_file):
            continue
        logger.debug("Trying to authenticate with identity file %s", identity_file)
        try:
            self._pkey_auth(identity_file, password=self.password)
        except Exception as ex:
            logger.debug(
                "Authentication with identity file %s failed with %s, "
                "continuing with other identities",
                identity_file,
                ex,
            )
            continue
        else:
            logger.debug(
                "Authentication succeeded with identity file %s", identity_file
            )
            return
    raise AuthenticationError("No authentication methods succeeded")


# 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 _identity_auth(self):
    for identity_file in self.IDENTITIES:
        if not os.path.isfile(identity_file):
            continue
        logger.debug("Trying to authenticate with identity file %s", identity_file)
        try:
            self._pkey_auth(identity_file, password=self.password)
        except Exception as ex:
            logger.debug(
                "Authentication with identity file %s failed with %s, "
                "continuing with other identities",
                identity_file,
                ex,
            )
            continue
        else:
            logger.info("Authentication succeeded with identity file %s", identity_file)
            return
    raise AuthenticationError("No authentication methods succeeded")