# Buggy code
def _handle_prompt(self, resp, prompts, answer, newline):
    """
    Matches the command prompt and responds

    :arg resp: Byte string containing the raw response from the remote
    :arg prompts: Sequence of byte strings that we consider prompts for input
    :arg answer: Byte string to send back to the remote if we find a prompt.
            A carriage return is automatically appended to this string.
    :returns: True if a prompt was found in ``resp``.  False otherwise
    """
    if not isinstance(prompts, list):
        prompts = [prompts]
    prompts = [re.compile(r, re.I) for r in prompts]
    for regex in prompts:
        match = regex.search(resp)
        if match:
            self._ssh_shell.sendall(b"%s" % answer)
            if newline:
                self._ssh_shell.sendall(b"\r")
            return True
    return False


# Traceback (ConnectionError)
TASK [Config Using Core Module] ************************************************************************************************************************************************************
task path: /Users/gnalawad/targets/ios_interface.yml:21
<ios> attempting to start connection
<ios> using connection plugin network_cli
<ios> found existing local domain socket, using it!
<ios>
The full traceback is:
Traceback (most recent call last):
File "/Users/home/ansible/bin/ansible-connection", line 253, in main
messages.extend(conn.update_play_context(pc_data))
File "/Users/home/ansible/lib/ansible/module_utils/connection.py", line 146, in __rpc__
raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
ConnectionError: 'NoneType' object has no attribute 'endswith'

fatal: [ios]: FAILED! => {
"failed": true,
"msg": "'NoneType' object has no attribute 'endswith'"


The full traceback is:
Traceback (most recent call last):
File "/Users/home/ansible/bin/ansible-connection", line 253, in main
messages.extend(conn.update_play_context(pc_data))
File "/Users/home/ansible/lib/ansible/module_utils/connection.py", line 146, in __rpc__
raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
ConnectionError: unable to elevate privilege to enable mode, at prompt [None]

fatal: [ios]: FAILED! => {
"failed": true,
"msg": "unable to elevate privilege to enable mode, at prompt [None]"
}

# Fixed code
def _handle_prompt(self, resp, prompts, answer, newline, prompt_retry_check=False):
    """
    Matches the command prompt and responds

    :arg resp: Byte string containing the raw response from the remote
    :arg prompts: Sequence of byte strings that we consider prompts for input
    :arg answer: Byte string to send back to the remote if we find a prompt.
            A carriage return is automatically appended to this string.
    :returns: True if a prompt was found in ``resp``.  False otherwise
    """
    if not isinstance(prompts, list):
        prompts = [prompts]
    prompts = [re.compile(r, re.I) for r in prompts]
    for regex in prompts:
        match = regex.search(resp)
        if match:
            # if prompt_retry_check is enabled to check if same prompt is
            # repeated don't send answer again.
            if not prompt_retry_check:
                self._ssh_shell.sendall(b"%s" % answer)
                if newline:
                    self._ssh_shell.sendall(b"\r")
            self._matched_cmd_prompt = match.group()
            return True
    return False