Closed Arnohappy closed 7 months ago
Most of the time bunq slows down calls so a single threaded client does not hit the limit. Looks like now is a time when they don't, and the code that calculates the required delay looks broken. I've removed the old rate limit code and added a sleep for 3 seconds when a "Too many requests" exception occurs in this commit: https://github.com/wesselt/bunq2ynab/commit/8defd2b3576c06436d7fcc58c882426dd96e2a97
How does that work for you?
Yes, fix worked!
It looks like we potentially need to do something similar for YNAB?
I saw this in my logs:
Sep 15 22:22:47 Hoth python3[206267]: 2024-09-15 22:22:47,956 | DEBUG | ynab.py:34 | log_reply | {
Sep 15 22:22:47 Hoth python3[206267]: "error": {
Sep 15 22:22:47 Hoth python3[206267]: "id": "429",
Sep 15 22:22:47 Hoth python3[206267]: "name": "too_many_requests",
Sep 15 22:22:47 Hoth python3[206267]: "detail": "Too many requests"
Sep 15 22:22:47 Hoth python3[206267]: }
Sep 15 22:22:47 Hoth python3[206267]: }
Ah, actually, there is a retry mechanism, it just doesn't seem to help, as the same error keeps happening, even after:
Sep 15 22:32:51 Hoth python3[206267]: 2024-09-15 22:32:51,865 | ERROR | auto_sync.py:230 | <module> | Failed 6 times, waiting 3600 seconds for retry.
So I'm guessing it's the combined number of requests in that single action that are too many, so waiting to retry those combined number of requests isn't going to help here?
Edit 2: Actually, looking at the docs at https://api.ynab.com/#rate-limiting, it appears rate limiting is reset every clock hour, so the retry logic for YNAB can probably be smarter by calculating the time to wait until the next hour.
Thanks for your comment! I'm trying a year without YNAB, so I'm not using their API at the moment.
As I remember, when you hit the bunq rate limit you can just wait 3 seconds. It made sense to retry it within the normal program flow. I think when there was a problem with the rate limit calculation, I replaced it with just waiting 3 seconds and doing a retry when bunq raises a rate limit exception.
Not sure how to handle an hour wait time gracefully. Any idea why you hit that limit?
Got an error using the script on a server.
"Too many requests. You can do a maximum of 3 calls per 3 second to this endpoint".
Traceback (most recent call last): File "list_user.py", line 26, in
print_accounts(v)
File "list_user.py", line 12, in print_accounts
for a in bunq_api.get_accounts_for_user(u):
File "/home/forge/bunq2ynab/lib/bunq_api.py", line 113, in get_accounts_for_user
result = bunq.previous()
File "/home/forge/bunq2ynab/lib/bunq.py", line 231, in previous
return call('GET', older_url.lstrip("/"))
File "/home/forge/bunq2ynab/lib/bunq.py", line 210, in call
raise Exception(result["Error"][0]["error_description"])
Exception: Too many requests. You can do a maximum of 3 calls per 3 second to this endpoint.
It happens with all request, so also with the bunq2ynab.py script.
Can someone help me?