<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: python ssh catalyst 1300 netmiko fail in Code Exchange</title>
    <link>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264252#M153</link>
    <description>&lt;P&gt;Hi !&lt;/P&gt;&lt;P&gt;Thanks again !&lt;/P&gt;&lt;P&gt;Would probably work, but I ended up with taking a copy of "cisco_s300.py" to "cisco_s300_org.py".&amp;nbsp; Then copy "cisco_s200.py" to "cisco_s300.py.This is because we have no smb300 switches. Edited "cisco_s300.py" to this :&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;def special_login_handler(self, delay_factor: float = 1.0) -&amp;gt; None:&lt;BR /&gt;"""Cisco C13xx presents with the following on login&lt;/P&gt;&lt;P&gt;login as: user&lt;/P&gt;&lt;P&gt;User Name: user&lt;BR /&gt;Password:****&lt;BR /&gt;"""&lt;BR /&gt;output = ""&lt;BR /&gt;uname = "&lt;STRONG&gt;User&lt;/STRONG&gt;"&lt;BR /&gt;login = "login"&lt;BR /&gt;password = "ssword"&lt;BR /&gt;pattern = rf"(?:{uname}|{login}|{password}|{self.prompt_pattern})"&lt;/P&gt;&lt;P&gt;while True:&lt;BR /&gt;new_data = self.read_until_pattern(pattern=pattern, read_timeout=25.0)&lt;BR /&gt;output += new_data&lt;/P&gt;&lt;P&gt;# Fully logged-in, switch prompt detected.&lt;BR /&gt;if re.search(self.prompt_pattern, new_data):&lt;BR /&gt;return&lt;/P&gt;&lt;P&gt;if uname in new_data or login in new_data:&lt;BR /&gt;assert isinstance(self.username, str)&lt;BR /&gt;self.write_channel(self.username + self.RETURN)&lt;BR /&gt;elif password in new_data:&lt;BR /&gt;assert isinstance(self.password, str)&lt;BR /&gt;self.write_channel(self.password + self.RETURN)&lt;BR /&gt;else:&lt;BR /&gt;msg = f"""&lt;BR /&gt;Failed to login to Cisco C13xx.&lt;/P&gt;&lt;P&gt;Pattern not detected: {pattern}&lt;BR /&gt;output:&lt;/P&gt;&lt;P&gt;{output}&lt;/P&gt;&lt;P&gt;"""&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Probably not the best solution, but works ok &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Feb 2025 13:49:48 GMT</pubDate>
    <dc:creator>HaraldNordaas34991</dc:creator>
    <dc:date>2025-02-24T13:49:48Z</dc:date>
    <item>
      <title>python ssh catalyst 1300 netmiko fail</title>
      <link>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264156#M148</link>
      <description>&lt;P&gt;Hi !&lt;/P&gt;&lt;P&gt;Try to connect with Python (3.13) and netmiko (4.5.0) to Catalyst 1300 ( sw 4.1.6.53).&lt;/P&gt;&lt;P&gt;The problem is that first there is one prompt : "&lt;STRONG&gt;login as:&lt;/STRONG&gt;" and secondly a prompt : "&lt;STRONG&gt;User Name:&lt;/STRONG&gt;"&lt;/P&gt;&lt;P&gt;ssh = ConnectHandler(device_type='cisco_s200', ip=x.x.x.x, username=xx, password=xx, secret=xx, default_enter='\r', session_log= "debug_log.txt")&lt;/P&gt;&lt;P&gt;Error msg returned :&lt;/P&gt;&lt;P&gt;"&lt;EM&gt;Pattern not detected: '(?:Username:|login as|ssword|(?m:[&amp;gt;#]\\s*$))' in output.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Things you might try to fix this:&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;1. Adjust the regex pattern to better identify the terminating string. Note, in&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;many situations the pattern is automatically based on the network device's prompt.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;2. Increase the read_timeout to a larger value.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;You can also look at the Netmiko session_log or debug log for more information.&lt;/EM&gt;"&lt;/P&gt;&lt;P&gt;Tried to search for a solution with no luck.&lt;/P&gt;&lt;P&gt;Also looked at "cisco_base_connection.py",&amp;nbsp; but the variable "username_pattern" is only specified for serial and telnet.&lt;/P&gt;&lt;P&gt;Any help would be appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 09:51:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264156#M148</guid>
      <dc:creator>HaraldNordaas34991</dc:creator>
      <dc:date>2025-02-24T09:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: python ssh catalyst 1300 netmiko fail</title>
      <link>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264164#M149</link>
      <description>&lt;P&gt;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/1175094"&gt;@HaraldNordaas34991&lt;/a&gt;&amp;nbsp;i think your issue is that Netmiko default behavior is not designed for the two step authentication process. You would need to add to your code and exception to explicitly handle both prompts in sequence other than relying on Netmiko default pattern matching. You could try&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;from netmiko import ConnectHandler
from netmiko.base_connection import BaseConnection
import time

def _handle_login(self):
    """Handle the two-step authentication process"""
    
    # First prompt: "login as:"
    output = self.read_until_pattern(pattern=r"login as:")
    self.write_channel(self.username + self.RETURN)
    time.sleep(1)  # Small delay to ensure next prompt is ready
    
    # Second prompt: "User Name:"
    output = self.read_until_pattern(pattern=r"User Name:")
    self.write_channel(self.username + self.RETURN)
    time.sleep(1)  # Small delay before password prompt
    
    # Handle password prompt
    output = self.read_until_pattern(pattern=r"[Pp]assword:")
    self.write_channel(self.password + self.RETURN)
    
    return output

# Example usage with connection parameters
connection_params = {
    'device_type': 'cisco_s200',
    'ip': 'x.x.x.x',
    'username': 'your_username',
    'password': 'your_password',
    'secret': 'your_enable_secret',
    'default_enter': '\r',
    'session_log': 'debug_log.txt',
    'auth_timeout': 30,  # Increased timeout for auth process
}&lt;/LI-CODE&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 10:26:35 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264164#M149</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2025-02-24T10:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: python ssh catalyst 1300 netmiko fail</title>
      <link>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264167#M150</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Try this way&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; from netmiko import ConnectHandler&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ssh = ConnectHandler(device_type='cisco_s200',ip='x.x.x.x',username='xx',password='xx',secret='xx',timeout=10)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;You are mssing quotation marks on the varialble´s values.&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also try with&amp;nbsp;&lt;SPAN&gt;device_type='cisco_ios'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Another good way to put this is:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;from netmiko import ConnectHandler&lt;/P&gt;
&lt;P&gt;cisco_device = {&lt;BR /&gt;'device_type' : 'cisco_ios',&lt;BR /&gt;'ip': 'x.x.x.x',&lt;BR /&gt;'username' : 'xx',&lt;BR /&gt;'password' : 'xx',&lt;BR /&gt;'secret': 'xx'&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;ssh = ConnectHandler(**cisco_device)&lt;BR /&gt;onput = net_connect.send_command('show ip int brief')&lt;BR /&gt;print(onput)&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 10:31:55 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264167#M150</guid>
      <dc:creator>Flavio Miranda</dc:creator>
      <dc:date>2025-02-24T10:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: python ssh catalyst 1300 netmiko fail</title>
      <link>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264182#M151</link>
      <description>&lt;P&gt;Hi !&lt;/P&gt;&lt;P&gt;Thanks !&lt;/P&gt;&lt;P&gt;A very quick response, but is it possible to explain a bit more &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have added the extra line of code, but how should I change the connection so the "&lt;STRONG&gt;_handle_login(self)&lt;/STRONG&gt;"&amp;nbsp; is called ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ssh = ConnectHandler(device_type='cisco_s200', ip=x.x.x.x, username=xx, password=xx, secret=xx, default_enter='\r', session_log= "debug_log.txt", auth_timeout=30)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 10:57:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264182#M151</guid>
      <dc:creator>HaraldNordaas34991</dc:creator>
      <dc:date>2025-02-24T10:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: python ssh catalyst 1300 netmiko fail</title>
      <link>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264193#M152</link>
      <description>&lt;P&gt;Yes, The idea is to tell &lt;CODE&gt;ConnectHandler&lt;/CODE&gt; to use your custom class (&lt;CODE&gt;CiscoS200Connection&lt;/CODE&gt;) instead of the default class for &lt;CODE&gt;cisco_s200&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 11:08:58 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264193#M152</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2025-02-24T11:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: python ssh catalyst 1300 netmiko fail</title>
      <link>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264252#M153</link>
      <description>&lt;P&gt;Hi !&lt;/P&gt;&lt;P&gt;Thanks again !&lt;/P&gt;&lt;P&gt;Would probably work, but I ended up with taking a copy of "cisco_s300.py" to "cisco_s300_org.py".&amp;nbsp; Then copy "cisco_s200.py" to "cisco_s300.py.This is because we have no smb300 switches. Edited "cisco_s300.py" to this :&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;def special_login_handler(self, delay_factor: float = 1.0) -&amp;gt; None:&lt;BR /&gt;"""Cisco C13xx presents with the following on login&lt;/P&gt;&lt;P&gt;login as: user&lt;/P&gt;&lt;P&gt;User Name: user&lt;BR /&gt;Password:****&lt;BR /&gt;"""&lt;BR /&gt;output = ""&lt;BR /&gt;uname = "&lt;STRONG&gt;User&lt;/STRONG&gt;"&lt;BR /&gt;login = "login"&lt;BR /&gt;password = "ssword"&lt;BR /&gt;pattern = rf"(?:{uname}|{login}|{password}|{self.prompt_pattern})"&lt;/P&gt;&lt;P&gt;while True:&lt;BR /&gt;new_data = self.read_until_pattern(pattern=pattern, read_timeout=25.0)&lt;BR /&gt;output += new_data&lt;/P&gt;&lt;P&gt;# Fully logged-in, switch prompt detected.&lt;BR /&gt;if re.search(self.prompt_pattern, new_data):&lt;BR /&gt;return&lt;/P&gt;&lt;P&gt;if uname in new_data or login in new_data:&lt;BR /&gt;assert isinstance(self.username, str)&lt;BR /&gt;self.write_channel(self.username + self.RETURN)&lt;BR /&gt;elif password in new_data:&lt;BR /&gt;assert isinstance(self.password, str)&lt;BR /&gt;self.write_channel(self.password + self.RETURN)&lt;BR /&gt;else:&lt;BR /&gt;msg = f"""&lt;BR /&gt;Failed to login to Cisco C13xx.&lt;/P&gt;&lt;P&gt;Pattern not detected: {pattern}&lt;BR /&gt;output:&lt;/P&gt;&lt;P&gt;{output}&lt;/P&gt;&lt;P&gt;"""&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Probably not the best solution, but works ok &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 13:49:48 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264252#M153</guid>
      <dc:creator>HaraldNordaas34991</dc:creator>
      <dc:date>2025-02-24T13:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: python ssh catalyst 1300 netmiko fail</title>
      <link>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264280#M154</link>
      <description>&lt;P&gt;If it works, its great! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 14:50:54 GMT</pubDate>
      <guid>https://community.cisco.com/t5/code-exchange/python-ssh-catalyst-1300-netmiko-fail/m-p/5264280#M154</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2025-02-24T14:50:54Z</dc:date>
    </item>
  </channel>
</rss>

