Closed hustshawn closed 6 years ago
Hi hustshawn
It seems sanic-limiter0.1.2 is not adapt to sanic0.7, use sanic-limiter0.1.3 instead. pip install git+https://github.com/bohea/sanic-limiter
@bohea Thanks for your support. It works fine by using 0.13.
But may I know is it possible to make sanic just return a normal response object (eg. JSON output) with status code 429
, instead of just throw a Sanic Exception. Since currently, it is like
Error: too many request
it's a string, and even if I can customize the error message, but it is also have the Error: some message here
it would me more friendly if return a JSON response, like
{
"status": 429,
"message": "too many request"
}
@hustshawn
sanic_limiter can not return a normal response object, instead, sanic_limiter raise an exception
so you can handle it as you like, e.g:
from sanic_limiter import RateLimitExceeded
from sanic import response
@app.exception(RateLimitExceeded)
def handle_429(request, exception):
print("catch 429")
return response.json({
"status": 429,
"message": "too many request"
})
It looks great. Thank you for your help.
close
Hi! I know this issue is closed but I'm wondering if there is a plan to update the pypi package to be 0.1.3?
Limiter is working great so far, but it would be great to be able to rely on pypi in my production installs.
Thanks!
@psiofxt you may install 0.1.3 via pip now
Thank you so much @bohea ! You've saved me a ton of time with this package, I appreciate it.
Hi,
I just tried your package and introduced in my sanic app, but find it's not work. Below are my envrionment and demo code.
If call
/t1
, it expected to be 1 per minute and 5 per hour, but it will always be sucessfully called.Any idea what is wrong?