slowapi icon indicating copy to clipboard operation
slowapi copied to clipboard

Exception: No "request" or "websocket" argument on function

Open huths0lo opened this issue 1 year ago • 3 comments

Describe the bug If the rate limiter is not specifically instantiated as "limiter", it throws this error when adding an endpoint with the rate limiter decorator: Exception: No "request" or "websocket" argument on function

To Reproduce rate_limiter = Limiter(key_func=get_remote_address) app.state.limiter = rate_limiter app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)

@app.get("/home") @rate_limiter .limit("5/minute") async def homepage(request: Request): return { "message": "Hello world", }

Expected behavior The object should function regardless of what variable it is instantiated under.

Screenshots If applicable, add screenshots to help explain your problem.

Your app (please complete the following information):

  • fastapi or starlette? FastAPI
  • Version? 0.104.1
  • slowapi version (have you tried with the latest version)? 0.1.8 Additional context Add any other context about the problem here. I have just resorted to using the variable "limiter", which works fine.

huths0lo avatar Nov 27 '23 23:11 huths0lo

ever get this working?

esteininger avatar Jan 02 '24 01:01 esteininger

i got the same error; fastapi==0.109.2 slowapi==0.1.9

dl942702882 avatar Mar 15 '24 10:03 dl942702882

as i rename my api function params as 'request', i will pass the verification; its a not good verification

dl942702882 avatar Mar 15 '24 10:03 dl942702882