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

Limit Http Headers #18

Closed
moayyadfaris opened this issue Nov 2, 2020 · 5 comments · Fixed by #19
Closed

Limit Http Headers #18

moayyadfaris opened this issue Nov 2, 2020 · 5 comments · Fixed by #19

Comments

@moayyadfaris
Copy link

moayyadfaris commented Nov 2, 2020

I'm setting a rate limit for a route as below

from slowapi import Limiter, _rate_limit_exceeded_handler
from slowapi.util import get_remote_address
limiter = Limiter(key_func=get_remote_address, headers_enabled=True)

@router.post("/send-verification-otp", response_model=schemas.Msg)
@limiter.limit("1/1 minute")
def send_verification_otp(

Check the below error:

AttributeError: 'dict' object has no attribute 'headers'

@laurentS
Copy link
Owner

laurentS commented Nov 2, 2020

@moayyadfaris could you share the full stack trace, to help understand what the error is?

@moayyadfaris
Copy link
Author

moayyadfaris commented Nov 3, 2020

@laurentS
Code snippet:

alt text

Below is the error stack:

alt text

@moayyadfaris
Copy link
Author

@laurentS Any update 😇

@laurentS
Copy link
Owner

laurentS commented Nov 8, 2020

I haven't had time to check yet. My gut feeling would be to check your versions of starlette/fastapi vs the ones i have in the project.toml for slowapi, and see if the data type for response has changed in any way. If not, I'll have to check in more detail.

@glinmac
Copy link
Collaborator

glinmac commented Dec 19, 2020

@laurentS @moayyadfaris I faced the same issue with the decorator when the endpoint doesn't return an instance of Response. This is a valid FastAPI construct and it lets FastAPI do the transformation into a response_model or as needed later in the middleware stack.

@moayyadfaris did it happen in this context (not sure if it is as we can't see the content of your send_verification_otp function)?

Hopefully, I think that #19 should address it.

laurentS added a commit that referenced this issue Dec 23, 2020
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

Successfully merging a pull request may close this issue.

3 participants