Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rate limit reached #19

Open
Want100Cookies opened this issue Mar 18, 2024 · 5 comments
Open

Rate limit reached #19

Want100Cookies opened this issue Mar 18, 2024 · 5 comments

Comments

@Want100Cookies
Copy link

I noticed that the integration hit the rate-limit this weekend. I saw the following in the logging:

This error originated from a custom integration.

Logger: custom_components.bunq
Source: helpers/update_coordinator.py:350
integration: bunq (documentation)
First occurred: March 15, 2024 at 16:25:14 (20 occurrences)
Last logged: 08:48:06

Error fetching bunq data: Invalid response from API: Rate limit error has occurred with the Bunq API
Error fetching bunq data: Invalid response from API: Timeout occurred while connecting to the Bunq API
Error fetching bunq data: Invalid response from API: (502, {'message': '<html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body>\r\n<center><h1>502 Bad Gateway</h1></center>\r\n</body>\r\n</html>\r\n'})

I have allowed access to 4 monetary accounts and 3 cards.

@sstolk90
Copy link

The integration is also not working here with 15+ accounts

@ben8p
Copy link
Owner

ben8p commented Mar 26, 2024

Thanks for reporting.
I will dig into asap

@ben8p
Copy link
Owner

ben8p commented May 5, 2024

I am not sure how to tackle that one.

Here are the limits from bunq api:

If you are receiving the error 429, please make sure you are sending requests at rates that are below our rate limits.

Our rate limits per IP address per endpoint:

GET requests: 3 within any 3 consecutive seconds
POST requests: 5 within any 3 consecutive seconds
PUT requests: 2 within any 3 consecutive seconds
Callbacks: 2 callback URLs per notification category
We have a lower rate limit for /session-server: 1 request within 30 consecutive seconds.

https://doc.bunq.com/#/moving-to-production:~:text=what%20went%20wrong.-,Rate%20limits,-If%20you%20are

Currently the code use a 55 seconds delay between updates.
At each tick, it refreshes the accounts (1 GET request), the cards (1 GET request) and the transactions (1 GET request per account).

I wonder if time.sleep can be used in _fetch_monetary_account_transactions...

The setup for dev account with bunq is a bit annoying and I lost all my config recently.
Since this is a low risk change, I'd be willing to test it with prod api but I don't have enough accounts to make it fail.
Would one of you (@Want100Cookies / @sstolk90 ) have the skill to change the integration file in your HA and give it a try ?

The change is pretty easy.
See https://github.com/ben8p/home-assistant-bunq-balance-sensors/pull/23/files

@Want100Cookies
Copy link
Author

I have put in the code as mentioned. I must say that a few weeks ago everything went back to working, so I am afraid I have no baseline. Everything is still working after the patch, I will monitor it more closely the coming week. I do get the following log entry:

Logger: homeassistant.util.loop
Source: util/loop.py:99
First occurred: 10:43:35 (4 occurrences)
Last logged: 10:43:44

Detected blocking call to sleep inside the event loop by custom integration 'bunq' at custom_components/bunq/bunq_api.py, line 251: time.sleep(3) (offender: /config/custom_components/bunq/bunq_api.py, line 251: time.sleep(3)), please report it to the author of the 'bunq' custom integration

@ben8p
Copy link
Owner

ben8p commented May 6, 2024

Thanks a lot,
I was expecting this log. The code change to avoid it would be much larger.

Interesting that things started to work again. I wonder what has changed...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants