pyunifi icon indicating copy to clipboard operation
pyunifi copied to clipboard

Allow to define request timeout

Open Programie opened this issue 7 years ago • 4 comments

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?

Programie avatar Oct 20 '17 17:10 Programie

Great idea. I think this can be accomplished with the requests module. I will start playing with this...

Thanks!

finish06 avatar Oct 24 '17 17:10 finish06

I don't have much knowledge in Python, but maybe this will help: http://docs.python-requests.org/en/master/user/quickstart/#timeouts

Programie avatar Oct 25 '17 10:10 Programie

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.

vsnine avatar Nov 12 '17 21:11 vsnine

This is the pull request I came up with: https://github.com/finish06/pyunifi/pull/15

vsnine avatar Nov 12 '17 22:11 vsnine