Comments (4)
@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谢谢你打开这个。 您可以尝试更改路由处理程序的名称以使它们不同吗? 喜欢
channela
和channelb
例如?即使它们是 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.
This should help #13
from slowapi.
这应该有助于 #13
这应该有助于 #13
Thank you very much, this is a workable solution.
from slowapi.
Related Issues (20)
- Installation failure with poetry.core 1.5
- Can't set RATELIMIT_DEFAULT in .env HOT 4
- Dependency Dashboard
- Hi @smittysmee this is not my day job, it's 100% volunteer work, so priority may fall behind. The process for publishing an update is a bit manual still. If you want to give a hand with opening a PR to prepare for a release 0.1.8, I think a lot of people will be grateful. Examples from past releases #120 or #108. As a policy (see #58 ), I add any contributor who's had at least one PR merged to the repo, to help reduce bottlenecks. You're welcome to join the team!
- Features
- Feature | Can this support individual limits by IP address or user token? HOT 1
- slowapi uses limits==2.8.0 which contains usage of deprecated pkg_resources
- Bug: slowapi shared limiter does not accept callable for scope parameter HOT 3
- add multiple limiters on a single route. HOT 15
- The limiters of different routes with the same function name are confused, resulting in multiple checks HOT 1
- [Ehancement] Don't require `Request` parameter to be present in endpoint function signature. HOT 4
- Add as package in arch user repository
- Exception: No "request" or "websocket" argument on function HOT 3
- Need Rate Limiting on Basis of Request Body for a POST API HOT 1
- mypy error: type of `_rate_limit_exceeded_handler` is incompatible with latest starlette HOT 1
- Wrong parsing of limit_value when having more than one decorator HOT 1
- `request` parameter unable to be renamed HOT 1
- Consider avoiding BaseHTTPMiddleware as parent of SlowAPIMiddleware HOT 2
- [Feature request] - Limiter global `exempt_when` option
- {Token, User}-dependent rate limit control
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slowapi.