Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
huths0lo opened this issue Nov 27, 2023 · 4 comments
Open

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

huths0lo opened this issue Nov 27, 2023 · 4 comments

Comments

@huths0lo
Copy link

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.
@esteininger
Copy link

ever get this working?

@dl942702882
Copy link

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

@dl942702882
Copy link

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

@AnalyticAce
Copy link

Hey @huths0lo, I ran into the same problem. I solved it by adding a Request object to the param of the function:

Example Below:

from fastapi import APIRouter, Request
from routers.limiter import limiter

health_check = APIRouter(
    prefix="/health",
    tags=["Health Check"]
)

@health_check.get("/")
@limiter.limit('1/second')
async def health_check(request: Request):
    return {"message": "Server is running :) !"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants