nickovs / unificontrol

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

calling logout() results in error 400 #20

Open kinslayer1982 opened 3 years ago

kinslayer1982 commented 3 years ago

Hey,

for periodic requests to the unifi controller I made a script that logs in, fetches the required data and logs out. Everything works up to calling client.logout(), then I get the following:

Traceback (most recent call last): File "test.py", line 12, in client.logout() File "/home/sensor_bot/.local/share/virtualenvs/sensor_bot-ejTj32CH/lib/python3.7/site-packages/unificontrol/metaprogram.py", line 125, in wrapper return instance(client, *a, **kw) File "/home/sensor_bot/.local/share/virtualenvs/sensor_bot-ejTj32CH/lib/python3.7/site-packages/unificontrol/metaprogram.py", line 103, in call return client._execute(url, self._method, rest_dict, need_login=self._need_login) File "/home/sensor_bot/.local/share/virtualenvs/sensor_bot-ejTj32CH/lib/python3.7/site-packages/unificontrol/unifi.py", line 115, in _execute raise UnifiTransportError("{}: {}".format(resp.status_code, resp.reason)) unificontrol.exceptions.UnifiTransportError: 400:

Running the unifi controller on a raspberry pi, controller version: 6.0.45. Python 3.7

GabrielRRussell commented 2 years ago

Hmm... I'm having the same issue right now. It's a bit perplexing. It sounds stupid but honestly I found it easiest to just delete the current client, and recreate it. I need to actually test it out with multiple controllers, as my use case it like five of them, but so far it seems I'm able to log in, delete the client, re-initialize it, and it works just fine. Not sure if I'll run into any issues but if I do I will write it down here.

SKSEffertz commented 5 months ago

I had the same issue with the logout function. I compared the function call to the PHP version and the PHP version uses the POST method. This library uses the GET message.

Adding method="post", to the definition fixed it for me.