slowapi icon indicating copy to clipboard operation
slowapi copied to clipboard

limits more than specified

Open mandarup opened this issue 3 years ago • 4 comments

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?

mandarup avatar Jun 04 '21 01:06 mandarup

Hey, I know it is really a long time ago, but are you still having this issue?

danielqba avatar Jan 25 '22 07:01 danielqba

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.

samvr-pxl avatar Nov 15 '22 12:11 samvr-pxl

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

thentgesMindee avatar Nov 24 '22 12:11 thentgesMindee

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

samvr-pxl avatar Apr 03 '23 12:04 samvr-pxl