home-assistant-bunq-balance-sensors
home-assistant-bunq-balance-sensors copied to clipboard
Rate limit reached
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.
The integration is also not working here with 15+ accounts
Thanks for reporting. I will dig into asap
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
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
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...