foxel / python_ndms2_client

Keenetic NDMS v2 client connection library
MIT License
4 stars 7 forks source link

Error connecting to telnet server: No expected response from server #7

Open facetheheat opened 2 years ago

facetheheat commented 2 years ago

Hi there, Thanks for useful module. I've the Keenetic Peak KN-2710 with latest firmware v3.7.4 and Home Assistant server connected via wifi. I've enabled HA core plugin to connect in keenetic – keenetic_ndms2. And it won't to connect(mostly). Sometimes it connects well. I've started research this issue and found this module – it used in HA plugin. I've tried to reproduce the issue with this module.

$ cat ndms_list.py

from ndms2_client import Client, TelnetConnection
conn = TelnetConnection('192.168.1.1', 23, 'ha_automation', 'password', timeout=20)
client = Client(conn)
print(client.get_devices())

$ while true; do python3 ndms_list.py; done

... returns devices
... returns devices
... error
Error connecting to telnet server: No expected response from server
Traceback (most recent call last):
File "/Users/mac/Downloads/ndms_list.py", line 6, in <module>
print(client.get_devices())
File "/opt/homebrew/lib/python3.9/site-packages/ndms2_client/client.py", line 130, in get_devices
devices = _merge_devices(devices, self.get_hotspot_devices())
File "/opt/homebrew/lib/python3.9/site-packages/ndms2_client/client.py", line 143, in get_hotspot_devices
hotspot_info = self.__get_hotspot_info()
File "/opt/homebrew/lib/python3.9/site-packages/ndms2_client/client.py", line 200, in __get_hotspot_info
info = _parse_dict_lines(self._connection.run_command(_HOTSPOT_CMD))
File "/opt/homebrew/lib/python3.9/site-packages/ndms2_client/connection.py", line 52, in run_command
self.connect()
File "/opt/homebrew/lib/python3.9/site-packages/ndms2_client/connection.py", line 83, in connect
raise ConnectionException(message) from None
... returns devices
... returns devices
... returns devices
... returns devices

I've tried to increase connection timeout, but nothing changed.

eliahru commented 2 years ago

That's exactly the reason why I asked to review if it is possible to rewrite the library to connect to routers via API rather than SSH.

The problem is not related with timeout, but with strange behavior of Keenetic routers when they output a login prompt, but in fact do not accept any input for a couple of seconds after that. This causes the library to fail to authenticate since it outputs the credentials instantly when the prompt appears.

foxel commented 1 year ago

@facetheheat can you check your issue with 0.1.2 version?

facetheheat commented 1 year ago

Yep. Tested with 0.1.2 and all works fine