pynetgear icon indicating copy to clipboard operation
pynetgear copied to clipboard

Router webui not accessible after using pynetgear

Open flamechair opened this issue 5 years ago • 16 comments

Version: 0.5.2 Router: Netgear R8000 Use case: homeassistant 0.89.2 device tracker

When I configured my device tracker and booted up homeassistant, I can no longer access the router's web ui via direct IP or routerlogin.net but accessing the device via pynetgear works just fine

I can ping the device just fine, but accessing the web ui fails with a connection refused message. Stopping homeassistant doesn't resolve the issue either. Rebooting the router allows me to access the web ui again at least until I turn homeassistant back on

flamechair avatar Mar 16 '19 03:03 flamechair

this has been happening to me for quite some time as well on my r8000 when enabled via HA

JerLarge avatar Mar 20 '19 16:03 JerLarge

@iamtpage @JerLarge Hum. Perhaps reduce the polling time could help somehow ? By stopping homeassistant, and using pynetgear directly every 20s can you reproduce the same behavior ? If yes you can use v0.6.1 that I just released to test forcing cookie-based authentication, and see if it works with that: python -m pynetgear --password yourpass --login-v2 attached_devices

MatMaul avatar Mar 20 '19 23:03 MatMaul

Notice that the CLI has completely changed thanks to @liaden :-)

MatMaul avatar Mar 20 '19 23:03 MatMaul

i had it set in HA to interval_seconds: 180 and it was still doing it. i actually tried this via CLI on v0.6.0 this afternoon and couldnt get it to connect at all. i updated my r8000 today to v1.0.4.28_10.1.54 to see if that would fix it, it doesnt.

i had to use the --no-ssl flag, and that returns the list

i wrote a script to call it every 20 seconds, and tell me what iteration it is on, but that still means i need to check if it kills the UI, which im not sure when it does that normally.

ill periodically check it. so far it hasnt went down, though my program failed after 338 tries @20 seconds between them

JerLarge avatar Mar 21 '19 05:03 JerLarge

left it over night, and everything works fine still (iteration 1150 currently) and counting

JerLarge avatar Mar 21 '19 12:03 JerLarge

Let me know if there is anything that is unclear or missing from the CLI and I can try to make a fix to improve it. This first round was the best I could think of from my own perspective.

liaden avatar Mar 21 '19 15:03 liaden

@JerLarge ok so the difference between CLI and HA is that the login is done each time on CLI. Let's try to reproduce with this little script that more closely emulate HA behaviour, it should trigger the problem. You need pynetgear 0.6.1.

import pynetgear
import time

n = pynetgear.Netgear(password="", force_login_v2=False)

while True:
    print(n.get_attached_devices())
    time.sleep(20)

Then try to change force_login_v2 to True and see if it fixes the problem.

MatMaul avatar Mar 21 '19 17:03 MatMaul

perfect, that is almost exactly what i was using as a script, except i had something to count each loop through

JerLarge avatar Mar 21 '19 18:03 JerLarge

@JerLarge So you can't reproduce with that ? Are you sure you are not instantiating Netgear on each loop ?

If not are you running that on your computer or on the home-assistant host ? It makes a huge difference since the login v1 bind the login to the IP.

MatMaul avatar Mar 22 '19 14:03 MatMaul

I am running

`import pynetgear, time from pynetgear import Netgear

netgear = Netgear(password='password', force_login_v2=True)

x=0 while True: for i in netgear.get_attached_devices(): print (i)

time.sleep(20)
print (x)
x+=1`

and then i have another one that i switched too, which is the same but with force_login_v2=False

i have it disabled in HA and have for a few months. Im just running on the script on the server that runs HA

JerLarge avatar Mar 22 '19 14:03 JerLarge

and neither of those replicate the error, though the script fails at somepoint

here is v1 (force_login_v2=false) that ran since last night 1773 Error talking to API Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 601, in urlopen chunked=chunked) File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 387, in _make_request six.raise_from(e, None) File "", line 2, in raise_from File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 383, in _make_request httplib_response = conn.getresponse() File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse response.begin() File "/usr/lib/python3.5/http/client.py", line 297, in begin version, status, reason = self._read_status() File "/usr/lib/python3.5/http/client.py", line 258, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/usr/lib/python3.5/socket.py", line 575, in readinto return self._sock.recv_into(b) ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 440, in send timeout=timeout File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 639, in urlopen _stacktrace=sys.exc_info()[2]) File "/usr/local/lib/python3.5/dist-packages/urllib3/util/retry.py", line 357, in increment raise six.reraise(type(error), error, _stacktrace) File "/usr/local/lib/python3.5/dist-packages/urllib3/packages/six.py", line 685, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 601, in urlopen chunked=chunked) File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 387, in _make_request six.raise_from(e, None) File "", line 2, in raise_from File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 383, in _make_request httplib_response = conn.getresponse() File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse response.begin() File "/usr/lib/python3.5/http/client.py", line 297, in begin version, status, reason = self._read_status() File "/usr/lib/python3.5/http/client.py", line 258, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/usr/lib/python3.5/socket.py", line 575, in readinto return self._sock.recv_into(b) urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/pynetgear/init.py", line 375, in _make_request data=message, timeout=30, verify=False) File "/usr/local/lib/python3.5/dist-packages/requests/api.py", line 112, in post return request('post', url, data=data, json=json, **kwargs) File "/usr/local/lib/python3.5/dist-packages/requests/api.py", line 58, in request return session.request(method=method, url=url, **kwargs) File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 508, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 618, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 490, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) Get attached devices failed Traceback (most recent call last): File "pynetgeartestscriptv1.py", line 8, in for i in netgear.get_attached_devices(): TypeError: 'NoneType' object is not iterable

JerLarge avatar Mar 22 '19 14:03 JerLarge

I have absolutely no clue. The HA plugin does the same or I am missing something. Perhaps just trying to bump the version to 0.6.1 in home-assistant but I am pretty sure it will not fix it. (you need to modify the HA netgear py file, not only install with pip or HA will overrides it with the specified version on startup)

MatMaul avatar Mar 22 '19 15:03 MatMaul

and neither of those replicate the error, though the script fails at somepoint

here is v1 (force_login_v2=false) that ran since last night 1773 Error talking to API Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 601, in urlopen chunked=chunked) File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 387, in _make_request six.raise_from(e, None) File "", line 2, in raise_from File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 383, in _make_request httplib_response = conn.getresponse() File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse response.begin() File "/usr/lib/python3.5/http/client.py", line 297, in begin version, status, reason = self._read_status() File "/usr/lib/python3.5/http/client.py", line 258, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/usr/lib/python3.5/socket.py", line 575, in readinto return self._sock.recv_into(b) ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 440, in send timeout=timeout File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 639, in urlopen _stacktrace=sys.exc_info()[2]) File "/usr/local/lib/python3.5/dist-packages/urllib3/util/retry.py", line 357, in increment raise six.reraise(type(error), error, _stacktrace) File "/usr/local/lib/python3.5/dist-packages/urllib3/packages/six.py", line 685, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 601, in urlopen chunked=chunked) File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 387, in _make_request six.raise_from(e, None) File "", line 2, in raise_from File "/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py", line 383, in _make_request httplib_response = conn.getresponse() File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse response.begin() File "/usr/lib/python3.5/http/client.py", line 297, in begin version, status, reason = self._read_status() File "/usr/lib/python3.5/http/client.py", line 258, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/usr/lib/python3.5/socket.py", line 575, in readinto return self._sock.recv_into(b) urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/pynetgear/init.py", line 375, in _make_request data=message, timeout=30, verify=False) File "/usr/local/lib/python3.5/dist-packages/requests/api.py", line 112, in post return request('post', url, data=data, json=json, **kwargs) File "/usr/local/lib/python3.5/dist-packages/requests/api.py", line 58, in request return session.request(method=method, url=url, **kwargs) File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 508, in request resp = self.send(prep, **send_kwargs) File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 618, in send r = adapter.send(request, **kwargs) File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 490, in send raise ConnectionError(err, request=request) requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) Get attached devices failed Traceback (most recent call last): File "pynetgeartestscriptv1.py", line 8, in for i in netgear.get_attached_devices(): TypeError: 'NoneType' object is not iterable

Those look like standard networking issues between the server and the R8000, not uncommon to see a few when you are iterating 1700+ times

I have absolutely no clue. The HA plugin does the same or I am missing something. Perhaps just trying to bump the version to 0.6.1 in home-assistant but I am pretty sure it will not fix it. (you need to modify the HA netgear py file, not only install with pip or HA will overrides it with the specified version on startup)

A better way to override would be to override the device tracker as a custom_component, that way you aren't editing core files.

flamechair avatar Mar 22 '19 15:03 flamechair

@JerLarge Oh and you can also try force_login_v2=True in home-assistant with 0.6.1 to see if it helps.

MatMaul avatar Mar 22 '19 16:03 MatMaul

@JerLarge also have you tried to configure your ha with nossl too ? Could be a stupid bug of your router with https.

MatMaul avatar Mar 22 '19 16:03 MatMaul

Is this issue still happening in pynetgear? In my nodejs version I also get reports of certain routers that lock-up when polled too often. You then need to power down/up the router to reset. This happens e.g. with the R7000 on recent firmwares (there are some reports that older R7000 firmware levels are more stable).

On other routers this locking-up doesn't happen at all.

By the way: in nodejs I use:

  • http over LAN interface only (so no ssl)
  • the new login method with cookie if the router supports it (urn:NETGEAR-ROUTER:service:DeviceConfig:1#SOAPLogin)
  • the new attachedDevices method if the router supports it (urn:NETGEAR-ROUTER:service:DeviceInfo:1#GetAttachDevice2)

gruijter avatar May 29 '19 10:05 gruijter