pyunifi
pyunifi copied to clipboard
Allow to define request timeout
Currently this library doesn't seem to support setting a request timeout. In case the Unifi Controller is not responding, a script using this library is waiting infinitely.
In my case I'm using this library in a small local check for Check_MK to monitor my access points. If the Unifi Controller is not responding, every check will start an additional Python process waiting for the Unifi Controller to respond which will soon end in having hundreds of processes waiting for the Unifi Controller.
Could you please add the possibility to specify the timeout for the API requests?
Great idea. I think this can be accomplished with the requests module. I will start playing with this...
Thanks!
I don't have much knowledge in Python, but maybe this will help: http://docs.python-requests.org/en/master/user/quickstart/#timeouts
I'd also like to add that if the module can't reach the UniFi Controller, in the case of the integration with Home Assistant, it causes the entire app to block, and without any noticeable error message. Took a while to find it.
Should be as simple as adding a "timeout=x" entry to each of the calls to requests. I've got a locally edited version of controller.py, i'll see about getting a pull request over to you.
This is the pull request I came up with: https://github.com/finish06/pyunifi/pull/15