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

Huawei special_login_handler is not logging in successfully #2711

Closed
quinntwohao opened this issue Mar 28, 2022 · 52 comments · Fixed by #2935
Closed

Huawei special_login_handler is not logging in successfully #2711

quinntwohao opened this issue Mar 28, 2022 · 52 comments · Fixed by #2935
Labels

Comments

@quinntwohao
Copy link

quinntwohao commented Mar 28, 2022

The system information is as follows:

  1. netmiko version: 4.0
  2. python 3.10
  3. window 11

error_print:

Traceback (most recent call last):
  File "E:\web_API\test.py", line 11, in <module>
    app.net_ssh_proxy(switch_json = switch_json, commands=commands)
  File "E:\web_API\app.py", line 25, in net_ssh_proxy
    with ConnectHandler(**device_info, sock=sock) as net_connect:
  File "E:\venv_02\lib\site-packages\netmiko\ssh_dispatcher.py", line 344, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
  File "E:\venv_02\lib\site-packages\netmiko\base_connection.py", line 434, in __init__
    self._open()
  File "E:\venv_02\lib\site-packages\netmiko\base_connection.py", line 439, in _open
    self.establish_connection()
  File "E:\venv_02\lib\site-packages\netmiko\base_connection.py", line 1092, in establish_connection
    self.special_login_handler()
  File "E:\venv_02\lib\site-packages\netmiko\huawei\huawei.py", line 105, in special_login_handler
    output = self.read_until_pattern(password_change_prompt)
  File "E:\venv_02\lib\site-packages\netmiko\base_connection.py", line 631, in read_until_pattern
    raise ReadException(msg)
netmiko.exceptions.ReadException: Unable to successfully split output based on pattern:
pattern=((Change now|Please choose))|([\]>]\s*$)
output='\nInfo: The max number of VTY users is 21, the number of current VTY users online is 2, and total number of terminal users online is 2.\n      The current login time is 2022-03-28 15:55:30+08:00.\n<xxxx_hostname>'
results=['\nInfo: The max number of VTY users is 21, the number of current VTY users online is 2, and total number of terminal users online is 2.\n      The current login time is 2022-03-28 15:55:30+08:00.\n<xxxx_hostname', None, None, '>', '']

test instanse
2. python 3.10
3. window 11
Netmiko 3.4.0 Release

out_print

no problem

@migmorales22
Copy link

migmorales22 commented Mar 30, 2022

are you trying to do it with Huawei device_type?

Cause I have the same problem.
Tes instance

  1. python 3.9.7
  2. Mac OS
  3. Netlike 4.0.0

**from netmiko import ConnectHandler
from getpass import getpass
from pprint import pprint

cisco1 = {
"device_type": "huawei",
"host": "10.179.28.2",
"username": "jmmorales",
"password": getpass(),
}

command = "display version"
with ConnectHandler(**cisco1) as net_connect:
print(net_connect.find_prompt())
# Use TextFSM to retrieve structured data
output = net_connect.send_command(command, use_textfsm=True)

#print()
pprint(output)
#print()

**

Output

*Exception has occurred: ReadException
Unable to successfully split output based on pattern:
pattern=((Change now|Please choose))|([]>]\s
$)
output='\nInfo: The max number of VTY users is 15, the number of current VTY users online is 2, and total number of terminal users online is 2.\n The current login time is 2022-03-29 18:05:20-06:00.\nInfo: The device is not enabled with secure boot, please enable it.\n'
results=['\nInfo: The max number of VTY users is 15, the number of current VTY users online is 2, and total number of terminal users online is 2.\n The current login time is 2022-03-29 18:05:20-06:00.\nInfo: The device is not enabled with secure boot, please enable it.\n<GNCYGTAJN2D2C02B02EII1', None, None, '>', '']
File "/Volumes/Extreme SSD/HP/Py/Interfaces LIBRES/ssh-multiple-sessions-textfsm/send_command_textfsm-huawei.py", line 14, in
with ConnectHandler(cisco1) as net_connect:

@ktbyers ktbyers changed the title netmiko.exceptions.ReadException: Unable to successfully split output based on pattern Huawei special_login_handler is not logging in successfully Mar 30, 2022
@ktbyers ktbyers added the bug label Mar 30, 2022
@ktbyers
Copy link
Owner

ktbyers commented Mar 30, 2022

Can one of you show me what the Huawei login looks like? In other words, if you login manually what does the CLI session look like?

@migmorales22
Copy link

migmorales22 commented Mar 30, 2022

Yeah sure,

There it is:

**jm@JMG-MBA ~ % ssh jmmorales@10.179.28.2

+----------------------------------------------------------------+
| Este equipo es propiedad privada, |
| si no tiene autorizacion para ingresar al equipo, por favor |
| cancele la conexion inmediatamente,cualquier anomalia sera |
| reportada a las autoridades correspondientes. |
+----------------------------------------------------------------+

User Authentication
(jmimorales@10.179.28.2) Enter password:

Warning: Negotiated identity key for server authentication is not safe. It is recommended that you disable the insecure algorithm or upgrade the client.

Info: The max number of VTY users is 15, the number of current VTY users online is 1, and total number of terminal users online is 1.
The current login time is 2022-03-29 21:09:19-06:00.
Info: The device is not enabled with secure boot, please enable it.
GNCYGTAJN2D2C02B02EII1>
**

@ktbyers
Copy link
Owner

ktbyers commented Mar 30, 2022

What is this ** after the prompt?

GNCYGTAJN2D2C02B02EII1>
**

Is that really there or was that an error in the posting above?

@migmorales22
Copy link

that was and error, those **** are not on the prompt.

Its because I wanna make the output to be in bold text.

@nivaldoinacios
Copy link

I have the same problem after having cloned the repository to another computer.

on the computer where I create the rep. it's working fine

I'm using another version of pycharm

@nivaldoinacios
Copy link

I managed to solve the problem.
I was connecting by ConnectionHandler and I switched to HuawelTelnet

@ktbyers
Copy link
Owner

ktbyers commented Mar 30, 2022

Does Netmiko 3.4.0 work (i.e. is this only a Netmiko 4.0.0 issue)?

@migmorales22

@migmorales22
Copy link

With netmiko 3.4.0 the data is not parse:

Here's the script:
from netmiko import ConnectHandler
from getpass import getpass
from pprint import pprint

cisco1 = {
"device_type": "huawei",
"host": "10.179.28.2",
"username": "huawei",
"password": getpass(),
}

command = "display version"
with ConnectHandler(**cisco1) as net_connect:
output = net_connect.send_command(command, use_textfsm=True)

print(output)

Here is the output:

Huawei Versatile Routing Platform Software
VRP (R) software, Version 8.190 (NE40E V800R011C10SPC100)
Copyright (C) 2012-2019 Huawei Technologies Co., Ltd.
HUAWEI NE40E-M2K-B uptime is 350 days, 18 hours, 31 minutes

NE40E-M2K-B version information:


BKP version information:
PCB Version : CX68BKP01D REV A
IPU Slot Quantity : 1
CARD Slot Quantity : 3


IPU version information:

IPU (Master) 3 : uptime is 350 days, 18 hours, 31 minutes
StartupTime 2021/04/13 18:22:50
SDRAM Memory Size : 16384 M bytes
FLASH Memory Size : 128 M bytes
CFCARD Memory Size : 4096 M bytes
IPU CR5B0BKP0393 version information
CPU PCB Version : CX68E4NLAXFB REV B
EPLD Version : 004
FPGA Version : 009
FPGA2 Version : 008
NPU PCB Version : CX68E4NLAXFA REV A
FPGA Version : 102
FPGA2 Version : 007
NP Version : 100
TM Version : 110
NSE Version : NSE REV A
BootROM Version : 04.73


Power version information:

POWER 4's version information:
PCB Version : CX68PSUF REV B

POWER 5's version information:
PCB Version : CX68PSUF REV B


FAN version information:

FAN 6's version information:
PCB Version : CX68FCBD REV A


CLK version information:

CLK 7 : uptime is 350 days, 18 hours, 31 minutes
StartupTime 2021/04/13 18:22:50
FPGA Version : 1509
DSP Version : 17060021
(project1) josemiguelmorales@MIG-MBA ~ %

With netmiko 4.0.0, and same script, the output is:

Exception has occurred: ReadException
Unable to successfully split output based on pattern:
pattern=((Change now|Please choose))|([]>]\s*$)
output='\nInfo: The max number of VTY users is 11, the number of current VTY users online is 1, and total number of terminal users online is 1.\n The current login time is 2022-03-30 12:56:58-04:00.\n The last login time is 2022-03-30 12:53:46-04:00 from 181.209.150.62 through SSH.\n'
results=['\nInfo: The max number of VTY users is 11, the number of current VTY users online is 1, and total number of terminal users online is 1.\n The current login time is 2022-03-30 12:56:58-04:00.\n The last login time is 2022-03-30 12:53:46-04:00 from 181.209.150.62 through SSH.\n<MARLLC01', None, None, '>', '']
File "/Volumes/Extreme SSD/HP/Py/Interfaces LIBRES/ssh-multiple-sessions-textfsm/send_command_textfsm-huawei.py", line 14, in
with ConnectHandler(**cisco1) as net_connect:

@ktbyers
Copy link
Owner

ktbyers commented Mar 31, 2022

@migmorales22 So in Netmiko 3.4.0, you connect, but your TextFSM parsing doesn't work properly (i.e. you have a different issue, but not a connection issue).

Is that correct?

@migmorales22
Copy link

Yes, that's correct,

With netmiko 3.4.0 its the textfsm that doesn't parse the output of the send command, and in netmiko 4.0.0 is the "Exception has occurred:ReadException"

@luweijun1992
Copy link

I couldn't connect to Huawei devices after upgrading to V4.0.0 .

@luweijun1992
Copy link

luweijun1992 commented Mar 31, 2022

Connecting to 192.168.1.100:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

WARNING! The remote SSH server rejected X11 forwarding request.

Info: The max number of VTY users is 10, and the number
      of current VTY users on line is 1.
      The current login time is 2022-03-31 15:03:24+08:00.
Info: Lastest accessed IP: 192.168.1.100  Time: 2022-03-31 14:58:54+08:00  Password will expire in: -

Info: Smart-upgrade is currently disabled. Enable Smart-upgrade to get recommended version information.
<HUAWEI>

@pyhas
Copy link

pyhas commented Apr 3, 2022

I have the same issue with Huawei device

@luweijun1992
Copy link

New version V4.0.0 has problems with huawei devices.
@ktbyers

@fharbe
Copy link
Contributor

fharbe commented Apr 4, 2022

I can confirm the issue using Netmiko 4.0.0 (latest pip release together with Python 3.10.4) using device_type = 'huawei'.

With the Netmiko 3.4.0 release everything works fine. Also, it doesn't seem to make any difference whether the password change prompt is displayed or not (see both tracebacks below).

netmiko.exceptions.ReadException: Unable to successfully split output based on pattern:
pattern=((Change now|Please choose))|([\]>]\s*$)
output='\nWarning: The password will expire in 11 days.\nThe password needs to be changed. Change now? [Y/N]: '
results=['\nWarning: The password will expire in 11 days.\nThe password needs to be changed. ', 'Change now', 'Change now', None, '? [Y/N]: ']
netmiko.exceptions.ReadException: Unable to successfully split output based on pattern:
pattern=((Change now|Please choose))|([\]>]\s*$)
output='\nInfo: Current mode: Monitor (automatically making switching decisions).\nWarning: The intelligent upgrade function is disabled. Log in to the web platform and enable this function.\n  -----------------------------------------------------------------------------     \n  User last login information:     [...]      \n  -----------------------------------------------------------------------------\n<AC6508>'
results=['\nInfo: Current mode: Monitor (automatically making switching decisions).\nWarning: The intelligent upgrade function is disabled. Log in to the web platform and enable this function.\n  -----------------------------------------------------------------------------     \n  User last login information:     [...]    \n  -----------------------------------------------------------------------------\n<AC6508', None, None, '>', '']

After spending some time investigating the issue I found out that the pattern matching logic in read_until_pattern expects the pattern to split exactly in 3 parts (using re.split), see base_connection.py#L579 for reference. Seems this change was introduced during some fundamental changes to the channel reading logic in in 793100d.

I have proposed a fix and documented some more info in #2719.

@luweijun1992
Copy link

When will the new version be released.

@ktbyers
Copy link
Owner

ktbyers commented Apr 5, 2022

@luweijun1992 Just pin to Netmiko 3.4.0 or directly use the proposed fix from Git (i.e. you don't need a new release to work around this).

fharbe added a commit to fharbe/netmiko that referenced this issue Apr 5, 2022
fharbe added a commit to fharbe/netmiko that referenced this issue Apr 5, 2022
@luweijun1992
Copy link

@luweijun1992 Just pin to Netmiko 3.4.0 or directly use the proposed fix from Git (i.e. you don't need a new release to work around this).

I installed it using pip, do you mean rollback version v3.4.0?
Still want to use the new version, need the new function send_multiline()

@fharbe
Copy link
Contributor

fharbe commented Apr 6, 2022

@luweijun1992 You could use my proposed fix directly with pip like below until a fixed Netmiko version is available.

pip install 'git+https://github.com/fharbe/netmiko.git@fix_huawei_login#egg=netmiko'

@ktbyers
Copy link
Owner

ktbyers commented Apr 12, 2022

Updated PR here:

#2728

Can anyone test that this works properly?

@ktbyers
Copy link
Owner

ktbyers commented Apr 14, 2022

@luweijun1992 @pyhas @migmorales22 @nivaldoinacios @quinnhao Let me know is someone can test the PR here:

#2728

I want to try to include this in a Netmiko release that I would release shortly.

Thanks, Kirk

@luweijun1992
Copy link

@luweijun1992 @pyhas @migmorales22 @nivaldoinacios @quinnhao Let me know is someone can test the PR here:

#2728

I want to try to include this in a Netmiko release that I would release shortly.

Thanks, Kirk

Looking forward to the release of the new version, I go back to the old version v3.4.0

@ktbyers
Copy link
Owner

ktbyers commented Apr 14, 2022

@luweijun1992 Yep, I need someone to test that it fixes the issue. Can you do that?

@ktbyers
Copy link
Owner

ktbyers commented Apr 14, 2022

@luweijun1992 pip install it and see if the previous failure occurs or not.

You can pip install a specific commit. You can also pip install a branch. Some of this pip syntax is confusing, but should be available online. I usually do:

git clone <repo>
cd <repo>
pip uninstall netmiko
pip install -e .

i.e. I usually just install it from the local repository. You have to make sure you clone the right location. I will merge into the develop branch (right now). So the above should work (as git will clone the develop branch automatically).

ktbyers added a commit that referenced this issue Apr 14, 2022
* fix(huawei): fix special_login_handler (#2711)

* Relocate password change code back to special_login_handler

* Fix issue you could get into where prompt might not be available.

* Increase timeouts to allow for more time during initial read.

Remove the _test_channel_read()

* Removing ReadTimeout handling

Co-authored-by: Florian Harbecke <florian@harbecke.net>
@luweijun1992
Copy link

@luweijun1992 pip install it and see if the previous failure occurs or not.

You can pip install a specific commit. You can also pip install a branch. Some of this pip syntax is confusing, but should be available online. I usually do:

git clone <repo>
cd <repo>
pip uninstall netmiko
pip install -e .

i.e. I usually just install it from the local repository. You have to make sure you clone the right location. I will merge into the develop branch (right now). So the above should work (as git will clone the develop branch automatically).

git clone https://github.com/ktbyers/netmiko.git
cd netmiko
pip install -e .

image

[Running] python -u "d:\ssh_conn.py"
Traceback (most recent call last):
  File "d:\ssh_conn.py", line 26, in <module>
    with ConnectHandler(**huawei) as net_connect:
  File "d:\netmiko\netmiko\ssh_dispatcher.py", line 344, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
  File "d:\netmiko\netmiko\base_connection.py", line 434, in __init__
    self._open()
  File "d:\netmiko\netmiko\base_connection.py", line 439, in _open
    self.establish_connection()
  File "d:\netmiko\netmiko\base_connection.py", line 1092, in establish_connection
    self.special_login_handler()
  File "d:\netmiko\netmiko\huawei\huawei.py", line 18, in special_login_handler
    data = self.read_until_pattern(pattern=rf"({password_change_prompt}|[>\]])")
  File "d:\netmiko\netmiko\base_connection.py", line 631, in read_until_pattern
    raise ReadException(msg)
netmiko.exceptions.ReadException: Unable to successfully split output based on pattern:
pattern=((Change now|Please choose)|[>\]])
output='\nInfo: The max number of VTY users is 10, and the number\n      of current VTY users on line is 1.\n      The current login time is 2009-02-09 21:53:27+08:00.\n<S5700-10P>'
results=['\nInfo: The max number of VTY users is 10, and the number\n      of current VTY users on line is 1.\n      The current login time is 2009-02-09 21:53:27+08:00.\n<S5700-10P', '>', None, '']


[Done] exited with code=1 in 8.166 seconds

image

@ktbyers
Copy link
Owner

ktbyers commented Apr 15, 2022

@luweijun1992 Okay, great thanks for testing.

I have a new fix here:

#2737

This has been merged into develop.

You should be able to update your code that you are testing with by doing.

cd <github repo directory>
git fetch origin
git rebase origin/develop

This assumes you still have the develop branch checked out (which you should).

@ktbyers
Copy link
Owner

ktbyers commented Apr 15, 2022

If you could re-test this new fix, that would be very helpful.

@luweijun1992
Copy link

@luweijun1992 Okay, great thanks for testing.

I have a new fix here:

#2737

This has been merged into develop.

You should be able to update your code that you are testing with by doing.

cd <github repo directory>
git fetch origin
git rebase origin/develop

This assumes you still have the develop branch checked out (which you should).
The test was successful.
image

image

@luweijun1992
Copy link

@luweijun1992 Okay, great thanks for testing.

I have a new fix here:

#2737

This has been merged into develop.

You should be able to update your code that you are testing with by doing.

cd <github repo directory>
git fetch origin
git rebase origin/develop

This assumes you still have the develop branch checked out (which you should).

But the result of print seems abnormal.

print(result)

image

@aztec102
Copy link

Hello!
@ktbyers 4.1.0 is ok work ssh, problem use huawei_telnet

Traceback (most recent call last):
  File "/home/mikholap/Рабочий стол/my-projects/mikholap-scripts/core and aggregation/asw_vlan_probros_pub.py", line 17, in <module>
    net_connect = ConnectHandler(**device)
  File "/home/mikholap/.local/lib/python3.10/site-packages/netmiko/ssh_dispatcher.py", line 344, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
  File "/home/mikholap/.local/lib/python3.10/site-packages/netmiko/base_connection.py", line 434, in __init__
    self._open()
  File "/home/mikholap/.local/lib/python3.10/site-packages/netmiko/base_connection.py", line 439, in _open
    self.establish_connection()
  File "/home/mikholap/.local/lib/python3.10/site-packages/netmiko/base_connection.py", line 1009, in establish_connection
    self.telnet_login()
  File "/home/mikholap/.local/lib/python3.10/site-packages/netmiko/huawei/huawei.py", line 150, in telnet_login
    output = self.read_until_pattern(pattern=combined_pattern)
  File "/home/mikholap/.local/lib/python3.10/site-packages/netmiko/base_connection.py", line 631, in read_until_pattern
    raise ReadException(msg)
netmiko.exceptions.ReadException: Unable to successfully split output based on pattern:
pattern=(]\s*$|>\s*$|(Change now|Please choose 'YES' or 'NO').+)
output=':\nInfo: The max number of VTY users is 10, and the number\n      of current VTY users on line is 2.\n      The current login time is 2022-05-13 13:46:34+04:00.\nInfo: Smart-upgrade is currently disabled. Enable Smart-upgrade to get recommended version information.\n<***>'
results=[':\nInfo: The max number of VTY users is 10, and the number\n      of current VTY users on line is 2.\n      The current login time is 2022-05-13 13:46:34+04:00.\nInfo: Smart-upgrade is currently disabled. Enable Smart-upgrade to get recommended version information.\n<***', '>', None, '']

@ktbyers
Copy link
Owner

ktbyers commented May 13, 2022

@aztec102 So you are still seeing an issue when you suing Huawei and telnet with Netmiko 4.1.0?

@aztec102
Copy link

@ktbyers Yes, i see.

import re
from netmiko import ConnectHandler
host = input('Input Dest host: ')

device = {
    'device_type': 'huawei_telnet',
    'ip':   host,
    'username': 'login',
    'password': 'pass',
    'port' : 23,
    'verbose': True,
    'session_log': f'{host}.log'
}

net_connect = ConnectHandler(**device)
pip3 list | grep netmiko
netmiko                      4.1.0

@zhtjames
Copy link

Hi!MR.Ktbyers!I have the same issue with H3C(hp_comware_telnet) .
SSH(hp_comware) was perfect ! I like it ! but telnet never succeeded.


from netmiko import ConnectHandler

dev = {
'device_type': "hp_comware_telnet",
'host': '192.168.11.1',
'username': 'admin',
'password': 'admin',
'port': 23,
}
net_con = ConnectHandler(**dev)
output = net_con.send_command('display current-configuration')
print(output)


Traceback (most recent call last):
File "C:\Users\18592\AppData\Roaming\JetBrains\PyCharm2022.1\scratches\scratch_6.py", line 10, in
net_con = ConnectHandler(**dev)
File "C:\Users\18592\PycharmProjects\thearding\venv\lib\site-packages\netmiko\ssh_dispatcher.py", line 351, in ConnectHandler
return ConnectionClass(*args, **kwargs)
File "C:\Users\18592\PycharmProjects\thearding\venv\lib\site-packages\netmiko\hp\hp_comware.py", line 145, in init
super().init(*args, **kwargs)
File "C:\Users\18592\PycharmProjects\thearding\venv\lib\site-packages\netmiko\hp\hp_comware.py", line 13, in init
super().init(**kwargs)
File "C:\Users\18592\PycharmProjects\thearding\venv\lib\site-packages\netmiko\base_connection.py", line 434, in init
self._open()
File "C:\Users\18592\PycharmProjects\thearding\venv\lib\site-packages\netmiko\base_connection.py", line 440, in _open
self._try_session_preparation()
File "C:\Users\18592\PycharmProjects\thearding\venv\lib\site-packages\netmiko\base_connection.py", line 879, in _try_session_preparation
self.session_preparation()
File "C:\Users\18592\PycharmProjects\thearding\venv\lib\site-packages\netmiko\hp\hp_comware.py", line 19, in session_preparation
data = self._test_channel_read(pattern=r"to continue|[>]]")
File "C:\Users\18592\PycharmProjects\thearding\venv\lib\site-packages\netmiko\base_connection.py", line 1119, in _test_channel_read
return self.read_until_pattern(pattern=pattern, read_timeout=20)
File "C:\Users\18592\PycharmProjects\thearding\venv\lib\site-packages\netmiko\base_connection.py", line 651, in read_until_pattern
raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:

Pattern not detected: 'to continue|[>\]]' 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.


1、windows 10
2、python3.10.4
3、netmiko 4.1.1
THANK YOU!

@ktbyers
Copy link
Owner

ktbyers commented Jun 30, 2022

@zhtjames Can you show me what a manual telnet looks like i.e. copy and paste the manual telnet session here. You can obscure/change your username and password or anything else that is confidential.

@ktbyers
Copy link
Owner

ktbyers commented Jun 30, 2022

@zhtjames ???

@TimGa
Copy link
Contributor

TimGa commented Aug 26, 2022

@ktbyers, you are great, thank you for netmiko!
I faced the same issue when try telnet. Below is manual telnet session you asked for:

user@my-secret-host:~$ telnet 10.166.66.66
Trying 10.166.66.66...
Connected to 10.166.66.66.
Escape character is '^]'.

Warning: Telnet is not a secure protocol, and it is recommended to use Stelnet.

Login authentication


Username:my-secret-username
Password:
Info: The max number of VTY users is 5, and the number
      of current VTY users on line is 1.
<my-secret-prompt>
<my-secret-prompt>quit
Info: The max number of VTY users is 5, and the number
      of current VTY users on line is 0.Connection closed by foreign host.
user@my-secret-host:~$

Python code:

from netmiko import ConnectHandler

device = {
    'device_type': 'huawei_telnet',
    'host': '10.166.66.66',
    'username': 'my-secret-username',
    'password': 'my-secret-password',
}

net_connect = ConnectHandler(**device)
net_connect.disconnect()

Exception:

Traceback (most recent call last):
  File "issue.py", line 10, in <module>
    net_connect = ConnectHandler(**device)
  File "/home/user/.local/lib/python3.8/site-packages/netmiko/ssh_dispatcher.py", line 365, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/netmiko/base_connection.py", line 439, in __init__
    self._open()
  File "/home/user/.local/lib/python3.8/site-packages/netmiko/base_connection.py", line 444, in _open
    self.establish_connection()
  File "/home/user/.local/lib/python3.8/site-packages/netmiko/base_connection.py", line 1034, in establish_connection
    self.telnet_login()
  File "/home/user/.local/lib/python3.8/site-packages/netmiko/huawei/huawei.py", line 155, in telnet_login
    output = self.read_until_pattern(pattern=combined_pattern)
  File "/home/user/.local/lib/python3.8/site-packages/netmiko/base_connection.py", line 672, in read_until_pattern
    raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout: 

Pattern not detected: "(]\\s*$|>\\s*$|(Change now|Please choose 'YES' or 'NO').+)" 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.

Configuration:

netmiko==4.1.2
Python 3.8.10
Linux Mint 20.3

@ktbyers
Copy link
Owner

ktbyers commented Aug 26, 2022

@TimGa Is it possible that you can look in the debugger and see what happened right before this:

https://github.com/ktbyers/netmiko/blob/develop/netmiko/huawei/huawei.py#L155

i.e. add a Pdb debug breakpoint right before this and see what is in the return_msg variable?

The failure above says it failed on the looking for > which should be in the output after the password is sent.

@TimGa
Copy link
Contributor

TimGa commented Aug 27, 2022

Here is return_msg content:


Warning: Telnet is not a secure protocol, and it is recommended to use Stelnet.


Login authentication


Username:my-secret-username
Password

It turned out that password in my python script was incorrect - I mixed up IPs and passwords of different devices while investigation. As far as I understood, ReadTimeout raises while waiting for pattern after incorrect password. And it looks like that in my case the reason for timeout is that device has big delay between asking for password re-entry.
Here is manual telnet with incorrect password, just in case:

Trying 10.166.66.66...
Connected to 10.166.66.66.
Escape character is '^]'.

Warning: Telnet is not a secure protocol, and it is recommended to use Stelnet.

Login authentication


Username:my-secret-username
Password:
Error: Local authentication is rejected

Username:my-secret-username
Password:
Error: Local authentication is rejected

Username:my-secret-username
Password:
Error: Local authentication is rejected
Connection closed by foreign host.

P.S. Sorry for the confusion! I was confused with "ReadTimeout:Pattern not detected:" and didn't even think about password issue, cause usually it is NetmikoAuthenticationException. So maybe it is better to raise auth instead of timeout in such situation, but offcourse it is up to you to decide.
Important: Actual problem is still remains - I can't connect to some huawei device using telnet, but actual error is not ReadTimeout but ReadException: Unable to successfully split output based on pattern. I'll try to investigate it and write results here in few days.

@ktbyers
Copy link
Owner

ktbyers commented Aug 28, 2022

I am going to leave this open and flag at it as an issue where improvement should be made.

  1. Better error message.
  2. Potentially more reliable loop behavior.

@Toxic-Waste-
Copy link

Hi all,

I seem to be running into this issue as well since the new version:

 File "/home/<snip>/devops/test-development/network/huawei_bulk_patch.py", line 19, in <module>
   print(net_connect = ConnectHandler(**device))
 File "/home/<snip>/.local/lib/python3.10/site-packages/netmiko/ssh_dispatcher.py", line 365, in ConnectHandler
   return ConnectionClass(*args, **kwargs)
 File "/home/<snip>/.local/lib/python3.10/site-packages/netmiko/base_connection.py", line 439, in __init__
   self._open()
 File "/home/<snip>/.local/lib/python3.10/site-packages/netmiko/base_connection.py", line 444, in _open
   self.establish_connection()
 File "/home/<snip>/.local/lib/python3.10/site-packages/netmiko/base_connection.py", line 1034, in establish_connection
   self.telnet_login()
 File "/home/<snip>/.local/lib/python3.10/site-packages/netmiko/huawei/huawei.py", line 155, in telnet_login
   output = self.read_until_pattern(pattern=combined_pattern)
 File "/home/<snip>/.local/lib/python3.10/site-packages/netmiko/base_connection.py", line 652, in read_until_pattern
   raise ReadException(msg)
netmiko.exceptions.ReadException: Unable to successfully split output based on pattern:
pattern=(]\s*$|>\s*$|(Change now|Please choose 'YES' or 'NO').+)
output=':\n  -----------------------------------------------------------------------------     \n  User last login information:     \n  -----------------------------------------------------------------------------\n  Access Type: Telnet      \n  IP-Address : <snip>     \n  Time       : 2022-08-29 11:21:20+02:00 DST     \n  -----------------------------------------------------------------------------\n<support-network-labo-ar1220>'
results=[':\n  -----------------------------------------------------------------------------     \n  User last login information:     \n  -----------------------------------------------------------------------------\n  Access Type: Telnet      \n  IP-Address : <snip>     \n  Time       : 2022-08-29 11:21:20+02:00 DST     \n  -----------------------------------------------------------------------------\n<support-network-labo-ar1220', '>', None, '']

Environment: Ubuntu 22.04.1
Python 3.10.4
netmiko 4.1.2

How can I help to investigate this? (not the best coder in the world but I will try to do my best)

@TimGa
Copy link
Contributor

TimGa commented Aug 30, 2022

The reason for Huawei telnet trouble netmiko.exceptions.ReadException: Unable to successfully split output based on pattern is that pattern (]\s*$|>\s*$|(Change now|Please choose 'YES' or 'NO').+) contains nested group (nested parentheses). To fix this issue, changes of source code needed.

Details:

  1. In this string:
    combined_pattern = r"({}|{}|{})".format(
    combined_pattern created - i mean this pattern (]\s*$|>\s*$|(Change now|Please choose 'YES' or 'NO').+)
  2. Then created combined_pattern passes to read_until_pattern method here
    output = self.read_until_pattern(pattern=combined_pattern)
  3. Bad thing happend here:
    results = re.split(pattern, output, maxsplit=1, flags=re_flags)
    After splitting, we got result list of length = 4, and this is the reason for ReadException here:
    if len(results) != 3:
  4. And the reason of len(result) = 4 is that combined_pattern has nested parentheses here:
(]\s*$|>\s*$|(Change now|Please choose 'YES' or 'NO').+)
             ^                                      ^

@Toxic-Waste- you can try to edit file /home/<snip>/.local/lib/python3.10/site-packages/netmiko/huawei/huawei.py on line 131
change this:

password_change_prompt = r"(Change now|Please choose 'YES' or 'NO').+"

to this:

password_change_prompt = r"Change now|Please choose 'YES' or 'NO'"

But you must understand that:

  • it is not good to change package's code directly like that
  • it can cause unexpected error in another place
  • this is just a dirty quick fix that worked for my case

@ktbyers I can try to analize side effects of proposed changes and craft Pull Request if you like. But if you think that PR is redundant, please let me know. Thanks!

@ktbyers
Copy link
Owner

ktbyers commented Aug 30, 2022

@TimGa Yeah, if you want to do a PR that is fine. We can also do a non-capture group like we did when we fixed the SSH Huawei driver here:

#2737

Might be less side-effects in doing the non-capture group (since that would change the regex pattern less)...but would need to look at it and test it some more.

TimGa added a commit to TimGa/netmiko that referenced this issue Sep 7, 2022
Incorrect nested groups in regex pattern "combined_pattern".
For details please see: ktbyers#2711 (comment)
@ammarhayder
Copy link

Hi all,

I seem to be running into this issue as well since the new version:

 File "/home/<snip>/devops/test-development/network/huawei_bulk_patch.py", line 19, in <module>
   print(net_connect = ConnectHandler(**device))
 File "/home/<snip>/.local/lib/python3.10/site-packages/netmiko/ssh_dispatcher.py", line 365, in ConnectHandler
   return ConnectionClass(*args, **kwargs)
 File "/home/<snip>/.local/lib/python3.10/site-packages/netmiko/base_connection.py", line 439, in __init__
   self._open()
 File "/home/<snip>/.local/lib/python3.10/site-packages/netmiko/base_connection.py", line 444, in _open
   self.establish_connection()
 File "/home/<snip>/.local/lib/python3.10/site-packages/netmiko/base_connection.py", line 1034, in establish_connection
   self.telnet_login()
 File "/home/<snip>/.local/lib/python3.10/site-packages/netmiko/huawei/huawei.py", line 155, in telnet_login
   output = self.read_until_pattern(pattern=combined_pattern)
 File "/home/<snip>/.local/lib/python3.10/site-packages/netmiko/base_connection.py", line 652, in read_until_pattern
   raise ReadException(msg)
netmiko.exceptions.ReadException: Unable to successfully split output based on pattern:
pattern=(]\s*$|>\s*$|(Change now|Please choose 'YES' or 'NO').+)
output=':\n  -----------------------------------------------------------------------------     \n  User last login information:     \n  -----------------------------------------------------------------------------\n  Access Type: Telnet      \n  IP-Address : <snip>     \n  Time       : 2022-08-29 11:21:20+02:00 DST     \n  -----------------------------------------------------------------------------\n<support-network-labo-ar1220>'
results=[':\n  -----------------------------------------------------------------------------     \n  User last login information:     \n  -----------------------------------------------------------------------------\n  Access Type: Telnet      \n  IP-Address : <snip>     \n  Time       : 2022-08-29 11:21:20+02:00 DST     \n  -----------------------------------------------------------------------------\n<support-network-labo-ar1220', '>', None, '']

Environment: Ubuntu 22.04.1 Python 3.10.4 netmiko 4.1.2

How can I help to investigate this? (not the best coder in the world but I will try to do my best)

To solve this problem you should use lib netmiko V 3.4.0 instead of netmiko V 4.0.0 >> to connect Huawei devices.

@zhtjames
Copy link

zhtjames commented Sep 14, 2022 via email

@aztec102
Copy link

@ammarhayder I'm still using version 3.4.0 because the versions above break the telnet connection for huawei

@ktbyers
Copy link
Owner

ktbyers commented Sep 14, 2022

There is a proposed fix for the Huawei telnet issue here:

#2935

If anyone else wants to test it.

@ktbyers
Copy link
Owner

ktbyers commented Sep 16, 2022

The telnet issue for Huawei should now be fixed here:

#2935

@ktbyers
Copy link
Owner

ktbyers commented Sep 16, 2022

I am going to lock conversions on this issue (as it is already way too long and already covers multiple issues).

If you are still running into Huawei issues, please create a new issue and reference details on the problem that you are encountering.

Repository owner locked and limited conversation to collaborators Sep 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.