Coder Social home page Coder Social logo

Comments (4)

laurentS avatar laurentS commented on July 18, 2024

@239144498 thanks for opening this. Can you try to change the name of the route handlers so that they are different? Like channela and channelb for instance?

Even if they are fastapi routes, they are still python functions, and they should have different names, otherwise, you're essentially overriding one function definition with the other.

from slowapi.

239144498 avatar 239144498 commented on July 18, 2024

@239144498谢谢你打开这个。 您可以尝试更改路由处理程序的名称以使它们不同吗? 喜欢 channelachannelb例如?

即使它们是 fastapi 路由,它们仍然是 python 函数,并且它们应该具有不同的名称,否则,您实际上是用另一个函数定义覆盖了一个函数定义。

Thanks for your answer, this problem is solved.
But I have one more question, the following code in

def check(request: Request):
    ip = limiter_key_func(request)
    if ip in whiteiplist:
        return True
    else:
        return False

@app.get('/demo1')
@limiter.limit("100/day", override_defaults=False, exempt_when=check)
async def channel(request: Request):
    return Response("A")

When I request interface demo1 the following error is reported.

File "xxxx\AppData\Local\Programs\Python\Python310\lib\site-packages\slowapi\extension.py", line 635, in async_wrapper
    self._check_request_limit(request, func, False)
  File "xxxx\AppData\Local\Programs\Python\Python310\lib\site-packages\slowapi\extension.py", line 535, in _check_request_limit
    self.__evaluate_limits(request, endpoint, all_limits)
  File "xxxx\AppData\Local\Programs\Python\Python310\lib\site-packages\slowapi\extension.py", line 405, in __evaluate_limits
    if lim.is_exempt:
  File "xxxx\AppData\Local\Programs\Python\Python310\lib\site-packages\slowapi\wrappers.py", line 38, in is_exempt
    return self.exempt_when() if self.exempt_when is not None else False
TypeError: check() missing 1 required positional argument: 'request'

What can I do to pass the request parameter to the check function?

from slowapi.

laurentS avatar laurentS commented on July 18, 2024

This should help #13

from slowapi.

239144498 avatar 239144498 commented on July 18, 2024

这应该有助于 #13

这应该有助于 #13

Thank you very much, this is a workable solution.

from slowapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.