finish06 / pyunifi

https://unifi-sdn.ubnt.com/
MIT License
223 stars 100 forks source link

Controller Login Fails with "Remote end closed connection without response" #11

Closed ChromoX closed 6 years ago

ChromoX commented 6 years ago

I have verified that I can login and have full use of the Unifi manager.

Whenever I try to initialize a Controller I would say I have a 1/6 chance of actually logging in. The other 5/6 times I simply have a trace-back that looks like the following:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 649, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 357, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.6/site-packages/urllib3/packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 386, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 382, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1331, in getresponse
    response.begin()
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))

I've been attempting to remedy this issue in some form which included me adding a couple of lines for a Requests adapter for max_retries, but this doesn't seem to actually help.

It could be related to https://github.com/requests/requests/issues/2422 and https://github.com/requests/requests/issues/2448

ChromoX commented 6 years ago

The POST requests(Only _login) are the only ones that have the above issues. Once logged in get requests have no problem.

finish06 commented 6 years ago

I have never been able to reproduce this issue. Have you gathered any additional information?

ChromoX commented 6 years ago

It might have been Docker networking stuff as the Unifi controller was in a container.

I switched over to using some module that uses ssh and goes direct to the AP instead of to the Unifi interface.

kocane commented 6 years ago

@ChromoX can you share with me how you solved your issues? I'm running in docker and am having some issues getting this to work aswell. Thanks,

ChromoX commented 6 years ago

I use this now instead of pyunifi: https://github.com/home-assistant/home-assistant/blob/master/homeassistant/components/device_tracker/unifi_direct.py