Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error seen when connecting to switch as not able to detect a prompt #3532

Open
pnikila opened this issue Nov 11, 2024 · 4 comments
Open

Error seen when connecting to switch as not able to detect a prompt #3532

pnikila opened this issue Nov 11, 2024 · 4 comments

Comments

@pnikila
Copy link

pnikila commented Nov 11, 2024

Description of Issue/Question

  1. I am connecting to cisco switch via console port.
  2. I am getting the below error :

An Error Occured:
Pattern not detected: '' in output.

Things you might try to fix this:

  1. Explicitly set your pattern using the expect_string argument.
  2. Increase the read_timeout to a larger value.

You can also look at the Netmiko session_log or debug log for more information.

An Error Occured: 'NoneType' object has no attribute 'write_channel'

  1. When manually try to connect to the switch, we have to press "Enter Key" and then console prompt comes.
  2. Now, when I again try to connect to the switch, I am able to connect to the switch.
  3. So, is there any way that when connecting to switch, netmiko gives "Enter" to detect prompt for connecting to device.

Setup

device_dict_cisco_serial = {
"device_type" : "terminal_server",
"ip":device_dict_cisco["serial_ip"],
"port":device_dict_cisco["serial_port"],
"username":device_dict_cisco["serial_username"],
"password":device_dict_cisco["serial_password"],
"global_delay_factor": 2,
"session_log":device_dict_cisco["session_log"],
"secret":device_dict_cisco["secret"],
"fast_cli":False
}
netmiko_dev = ConnectHandler(**device_dict_cisco_serial)
netmiko_dev.send_command('\n\n')
netmiko.redispatch(netmiko_dev, device_type=device_dict_cisco["device_type"])
return netmiko_dev

Netmiko version

(Paste verbatim output from pip freeze | grep netmiko between quotes below)

netmiko            4.4.0

Netmiko device_type (if relevant to the issue)

(Paste device_type between quotes below)

cisco_ios

Steps to Reproduce the Issue

1)Connect to serial console

Error Traceback

(Paste the complete traceback of the exception between quotes below)

An Error Occured:
Pattern not detected: '' in output.

Things you might try to fix this:
1. Explicitly set your pattern using the expect_string argument.
2. Increase the read_timeout to a larger value.

You can also look at the Netmiko session_log or debug log for more information.



An Error Occured: 'NoneType' object has no attribute 'write_channel'

Relevant Python code

(Please try to essentialize your Python code to the minimum code needed to reproduce the issue)
(Paste the code between the quotes below)

device_dict_cisco_serial = {
           "device_type" : "terminal_server",
                "ip":device_dict_cisco["serial_ip"],
                "port":device_dict_cisco["serial_port"],
                "username":device_dict_cisco["serial_username"],
                "password":device_dict_cisco["serial_password"],
                "global_delay_factor": 2,
                "session_log":device_dict_cisco["session_log"],
                "secret":device_dict_cisco["secret"],
                "fast_cli":False
            }
            netmiko_dev = ConnectHandler(**device_dict_cisco_serial)
            netmiko_dev.send_command('\n\n')
            netmiko.redispatch(netmiko_dev, device_type=device_dict_cisco["device_type"])
@ktbyers
Copy link
Owner

ktbyers commented Nov 11, 2024

Can you post the full exception stack trace (i.e. all the line numbers where the error occurred)? This let's me see where the error is occuring.

@pnikila
Copy link
Author

pnikila commented Nov 12, 2024

Traceback (most recent call last):

netmiko_dev.send_command('\n\n')

File "D:......\myvenv\Lib\site-packages\netmiko\base_connection.py", line 111, in wrapper_decorator

return_val = func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "D:....\myvenv\Lib\site-packages\netmiko\utilities.py", line 596, in wrapper_decorator
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:.....\myvenv\Lib\site-packages\netmiko\base_connection.py", line 1764, in send_command
search_pattern = self._prompt_handler(auto_find_prompt)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:....\myvenv\Lib\site-packages\netmiko\base_connection.py", line 1643, in _prompt_handler
prompt = self.find_prompt()
^^^^^^^^^^^^^^^^^^
File "D:.....\myvenv\Lib\site-packages\netmiko\base_connection.py", line 1439, in find_prompt
time.sleep(sleep_time)
KeyboardInterrupt

@pnikila
Copy link
Author

pnikila commented Nov 12, 2024

After removing the line netmiko_dev.send_command('\n\n') from code, we get this below error :

An Error Occured:

Pattern not detected: 'terminal width 511' in output.

Things you might try to fix this:

  1. Adjust the regex pattern to better identify the terminating string. Note, in
    many situations the pattern is automatically based on the network device's prompt.
  2. Increase the read_timeout to a larger value.

You can also look at the Netmiko session_log or debug log for more information.

An Error Occured: 'NoneType' object has no attribute 'write_channel'

In Netmiko log only this is present:
exit

@pnikila
Copy link
Author

pnikila commented Dec 2, 2024

Hi,
By using a loop to write_channel and read_channel , I am able to resolve this issue and connect to the device.
netmiko_dev.write_channel('\r')
time.sleep(1)
output = netmiko_dev.read_channel()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants