node-hue-api icon indicating copy to clipboard operation
node-hue-api copied to clipboard

ApiError: Problems resolving hue bridges, HTTP error status: 429

Open lexicalunit opened this issue 1 year ago • 12 comments

I have a CLI built using node-hue-api that has been working fine for months. Suddenly I'm getting rate limits now. I got a rate limit today and I haven't even run the CLI once today before that. The rate limits make no sense.

    at /opt/myapp/node_modules/node-hue-api/dist/cjs/api/discovery/nupnp.js:15:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async main (/opt/myapp/cli.js:44:21) {
  _hueError: undefine

lexicalunit avatar Jul 02 '22 03:07 lexicalunit

Same for me, identical error status and message. My script has been working fine for months until today.

pixlpirate avatar Jul 15 '22 22:07 pixlpirate

It is not the library; https://developers.meethue.com/rate-limiting-status-code/

peter-murray avatar Jul 26 '22 14:07 peter-murray

I have a complete lack of visibility to the use case here and the full manifestation of the error, can you provide some more context and a reproducible way for this error to be created?

peter-murray avatar Jul 26 '22 14:07 peter-murray

This is the code: https://github.com/lexicalunit/busylight/blob/main/cli.js

Essentially I'm just doing:

    const results = await discovery.nupnpSearch()
    const host = results[0].ipaddress
    const secure = await api.createLocal(host).connect(settings.username)
    const light = (await secure.lights.getLightByName(options.light))[0]
    const state = stateFromOptions(options)
    await secure.lights.setLightState(light.id, state)

lexicalunit avatar Jul 27 '22 17:07 lexicalunit

I'm experiencing the same issue when trying to develop an extension using this package. When I started today, everything was alright. But after several uses of discovery.nupnpSearch() I'm now getting the exact same issue.

For the record, all I've used for this error to appear up until this point is discovery.nupnpSearch().

pindab0ter avatar Jul 28 '22 15:07 pindab0ter

From the Hue documentation it looks to be active as of now:

NOTE 1 – UPnP (or more specifically the UPnP subset Simple Service Discovery Protocol (SSDP)) used to be available as another discovery method but has been deprecated in favor of mDNS and will be disabled in Q2 2022.

peter-murray avatar Aug 01 '22 11:08 peter-murray

That deprecation warning should no impact this particular endpoint, as the nupnp search is reaching out to the Hue cloud to get the data back for the known register bridges, https://discovery.meethue.com

They will have some level of rate limiting on this endpoint to stop abuse, but I cannot see any details on a rate limit documented anywhere. Do you know how many calls you are making before this starts to trigger?

peter-murray avatar Aug 01 '22 11:08 peter-murray

I managed to reproduce the rate limiting by hitting just the end point around 10 times in less than a minute. Hue are clearly protecting this endpoint now more than they used to, and it is technically an unauthenticated endpoint, so is a reasonable safety measure I guess to stop abuse...

That said, nothing that I am going to be able to remedy here, it is enforced by Hue themselves, I will take a look into the headers to see if there is any extra data about the rate limits, but nothing that I can change from the library side, Hue own the endpoint and can do whatever they like here.

peter-murray avatar Aug 01 '22 11:08 peter-murray

I just did a quick test and the limit seems to be 12. The thirteenth request fails. I don't know what the timeframe is.

pindab0ter avatar Aug 01 '22 11:08 pindab0ter

Nothing useful in the returned headers indicating a window, number of api calls remaining or reset time: Screenshot 2022-08-01 at 12 21 40

peter-murray avatar Aug 01 '22 11:08 peter-murray

I found this snippet buried in the Hue docs

The rate limit of using the discovery endpoint is maximum one request per 15 minutes per client. Typically it should be much less than that because the discovered IP can be stored and only rechecked when a request times out (as the ip might have changed). More regular ip scanning can always be done with mDNS.

peter-murray avatar Aug 01 '22 11:08 peter-murray

With the deprecation of the UPnP and the addition of mDNS, it looks like I will need to add that to the library as an alternative approach for discovery now.

peter-murray avatar Aug 01 '22 11:08 peter-murray

I have released a new version with mDNS support, see here for details https://github.com/peter-murray/node-hue-api/issues/221#issuecomment-1214181471

peter-murray avatar Aug 13 '22 16:08 peter-murray

Works great on my end! Discovery takes about 4s for me, every time. So maybe the default timeout could be a little more than 5s.

pindab0ter avatar Aug 14 '22 20:08 pindab0ter

Works great for me too!

lexicalunit avatar Aug 15 '22 18:08 lexicalunit