You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the example on the documentation page, the limit on a request to any of the endpoints adds 2 to the counter, this behavior can be corrected by making the name of the decoded functions different.
Extended version of the code from the documentation for reproduction:
from fastapi import FastAPI
from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.util import get_remote_address
from slowapi.errors import RateLimitExceeded
from fastapi import Request, Response
from fastapi.responses import PlainTextResponse
limiter = Limiter(key_func=get_remote_address)
app = FastAPI()
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
# Note: the route decorator must be above the limit decorator, not below it
@app.get("/home")
@limiter.limit("5/minute")
async def homepage(request: Request):
return PlainTextResponse("test")
@app.get("/mars")
@limiter.limit("5/minute")
async def homepage(request: Request, response: Response):
return {"key": "value"}
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="127.0.0.1", reload=False, port=int("8000"))
The text was updated successfully, but these errors were encountered:
In the example on the documentation page, the limit on a request to any of the endpoints adds 2 to the counter, this behavior can be corrected by making the name of the decoded functions different.
Extended version of the code from the documentation for reproduction:
The text was updated successfully, but these errors were encountered: