slowapi
slowapi copied to clipboard
limits more than specified
for some reason, I get half the rate specified. e.g 2/minute -> 1, 10/minute -> 5
This is my set up:
from fastapi import FastAPI, Request
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.util import get_remote_address
from slowapi.errors import RateLimitExceeded
limiter = Limiter(key_func=get_remote_address)
app = FastAPI()
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
@app.get("/")
@limiter.limit("5/minute")
async def root(request: Request):
return {"message": "Hello World"}
Is there anything obvious that I might be missing here?
Hey, I know it is really a long time ago, but are you still having this issue?
I'm still having this issue as well. But it's not always reproducible. I thought it had to do with the --reload
flag for setting up fastapi, but that was not it.
Hello @samvr-pxl could you also share how you run your server ? is it a development server ? using uvicorn ? That could help us find the reason
I'm sorry for not responding earlier. I had not seen your reply. Not sure if it's relevant anymore.
But I noticed it when setting up a fastai server with these commands:
uvicorn main:app --proxy-headers --host 0.0.0.0 --port 80 --reload
and
uvicorn main:app --proxy-headers --host 0.0.0.0 --port 80