unificontrol
unificontrol copied to clipboard
Can't get most of the calls working
So in the meantime I switched to a Debian VM instance just installed in order to get familiarized with the API. It is running in Python 3.11.2 venv. At first I could not get the SSL verification passing (CloudKey 7.2.97). So I applied this fix and then it passed. The first call used work with no issues
from unificontrol import UnifiClient
from datetime import timedelta
import json
import requests
from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
controller = UnifiClient(host='192.168.21.221', username='xx', password='yyyyyy', site='SaintPierre', cert=None)
sites = controller.list_sites()
print(sites)
Then I tried added various API calls without any success. I tried to set username and password again, no luck. For instance
controller.login()
devices= controller.list_devices_basic()
triggers an exception
Traceback (most recent call last):
File "/home/debian/environments/unificontroller/test.py", line 13, in <module>
devices= controller.list_devices_basic()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/debian/environments/unificontroller/lib/python3.11/site-packages/unificontrol/metaprogram.py", line 125, in wrapper
return instance(client, *a, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/debian/environments/unificontroller/lib/python3.11/site-packages/unificontrol/metaprogram.py", line 103, in __call__
return client._execute(url, self._method, rest_dict, need_login=self._need_login)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/debian/environments/unificontroller/lib/python3.11/site-packages/unificontrol/unifi.py", line 115, in _execute
raise UnifiTransportError("{}: {}".format(resp.status_code, resp.reason))
unificontrol.exceptions.UnifiTransportError: 401:
If I understand well there is a loggin issue. However I'm 100% sure of the credentials. What could be wrong then? Thank you
After some troubleshooting, I came to the conclusion that the "fix" masks the fact that login fails at first place. Line 96, I printed resp and it returns 401. So I go back to ssl validation which I think is the root cause. In the meantime I removed the "fix". Any thoughts? Thank you
Any help on this matter? Is there a way to get rid of ssl validation? Thank you
I'm unsure if this will solve your ssl validation issue, but I'm new to unificontrol and was having the same issue as you describe above. This issue https://github.com/nickovs/unificontrol/issues/11 inspired me to omit cert
and site
. For whatever reason, this worked for me. I hope this helps your situation.
>>> from unificontrol import UnifiClient
>>> client = UnifiClient(host="unifi.somewhere.io", username='admin', password='foobar')
>>> client.list_devices_basic()
>>> client.block_client('20:ff:bb:ed:dd:84')
>>> client.unblock_client('20:ff:bb:ed:dd:84')
The main problem here is that this code is 5 years old and since then the whole interface to the Unifi controller has been radically overhauled. Some of the calls are still compatible with the old API but to be honest the entire thing needs to be reworked. Also, it appears that the move to v8 of the controller changed the API endpoints again. Sadly I don't currently have the time to work on this.
I do understand the situation, thank you for your time.
I'm unsure if this will solve your ssl validation issue, but I'm new to unificontrol and was having the same issue as you describe above. This issue #11 inspired me to omit
cert
andsite
. For whatever reason, this worked for me. I hope this helps your situation.>>> from unificontrol import UnifiClient >>> client = UnifiClient(host="unifi.somewhere.io", username='admin', password='foobar') >>> client.list_devices_basic() >>> client.block_client('20:ff:bb:ed:dd:84') >>> client.unblock_client('20:ff:bb:ed:dd:84')
Thank you for your help. Unfortunately it does not work either. It si really a matter of the self signed certificate that has expired