netmiko: Huawei special_login_handler is not logging in successfully
The system information is as follows:
- netmiko version: 4.0
- python 3.10
- 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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 52 (26 by maintainers)
Commits related to this issue
- fix(huawei): fix special_login_handler (#2711) — committed to fharbe/netmiko by fharbe 2 years ago
- fix(huawei): fix special_login_handler (#2711) — committed to fharbe/netmiko by fharbe 2 years ago
- fix(huawei): fix special_login_handler (#2711) — committed to fharbe/netmiko by fharbe 2 years ago
- Updates to Huawei Login issue fix (#2728) * fix(huawei): fix special_login_handler (#2711) * Relocate password change code back to special_login_handler * Fix issue you could get into where pro... — committed to ktbyers/netmiko by ktbyers 2 years ago
- Fix ktbyers/netmiko issue #2711 Incorrect nested groups in regex pattern "combined_pattern". For details please see: https://github.com/ktbyers/netmiko/issues/2711#issuecomment-1231032715 — committed to TimGa/netmiko by TimGa 2 years ago
The reason for Huawei telnet trouble
netmiko.exceptions.ReadException: Unable to successfully split output based on patternis 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:
combined_patterncreated - i mean this pattern(]\s*$|>\s*$|(Change now|Please choose 'YES' or 'NO').+)combined_patternpasses toread_until_patternmethod here https://github.com/ktbyers/netmiko/blob/f3b5da244e6ce1e5fd7bd89fd36b090e854828b4/netmiko/huawei/huawei.py#L155resultlist of length = 4, and this is the reason forReadExceptionhere: https://github.com/ktbyers/netmiko/blob/f3b5da244e6ce1e5fd7bd89fd36b090e854828b4/netmiko/base_connection.py#L645result) = 4 is thatcombined_patternhas nested parentheses here:@Toxic-Waste- you can try to edit file
/home/<snip>/.local/lib/python3.10/site-packages/netmiko/huawei/huawei.pyon line 131 change this:to this:
But you must understand that:
@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 Yes, i see.
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).
After spending some time investigating the issue I found out that the pattern matching logic in
read_until_patternexpects 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 https://github.com/ktbyers/netmiko/commit/793100dcfd76d3eb5089ba4cd27c99e3c3c0f886.I have proposed a fix and documented some more info in #2719.