nickovs / unificontrol

A high-level Python interface to the Unifi controller software
Apache License 2.0
96 stars 41 forks source link

Attempts to retrieve get get 401 errors. #11

Closed chrisgilldc closed 4 years ago

chrisgilldc commented 4 years ago

Have run into an issue getting unificontrol up and running and am not sure if this is a common issue or if I'm just not doing something right. However I create the object, I wind up getting a Transport Error with a 401 code back.

I'd created a limited read-only user in Unifi for this, and on the chance that was breaking it, have tried using my regular super admin, but that doesn't work either, same issue. Instead I get the same error.

import unificontrol client = UnifiClient(host=<my Cloudcontroller>,username=<my regular user>,password=<my regular password>,site='Default') devices = client.list_devices()

And result:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.6/site-packages/unificontrol/metaprogram.py", line 123, in wrapper return instance(client, *a, **kw) File "/usr/local/lib/python3.6/site-packages/unificontrol/metaprogram.py", line 101, in __call__ return client._execute(url, self._method, rest_dict, need_login=self._need_login) File "/usr/local/lib/python3.6/site-packages/unificontrol/unifi.py", line 115, in _execute raise UnifiTransportError("{}: {}".format(resp.status_code, resp.reason)) unificontrol.exceptions.UnifiTransportError: 401:

The implication here is that the login isn't actually working or is being rejected for some reason, but unclear to me why. Note that the UnifiClient call itself does not error out - I only the error once I call list_devices (or any other call to get data). Same result if I call UnifiClient without user info and then call login explicitly with that info.

I can hack some python but am not enough of an expert to know all the ins and outs of what might be up here. Appreciate any guidance. Best.

nickovs commented 4 years ago

@chrisgilldc Sorry that you are having trouble. Can you tell me what version of the Unifi controller you are running?

nickovs commented 4 years ago

@chrisgilldc I think that the problem is that you put a capital 'D' on 'Default'. Try calling client.list_sites() and see if that works. The site parameter needs to be set to the site name, not the site description. The default site has a lower case 'd' for its name. I just tested this locally and if I supply site="Default" then I get the same error. Also note that if you just want the default site you can simply not set this argument when creating the client.

chrisgilldc commented 4 years ago

Ayup, that was it! Thanks!