小编U p*_*63A的帖子

如何根据方法参数应用速率限制

我正在使用 python 模块ratelimit来限制一个函数,该函数调用一个rest api,我需要根据请求的方法应用限制,例如每PUT/POST/DELETE10 秒 1 次,每GET1 秒 5 次,我怎样才能在不破坏功能一分为二?

from ratelimit import limits, sleep_and_retry

@sleep_and_retry
@limits(calls=1 if method != 'GET' else 5, period=10 if method != 'GET' else 1)
def callrest(method, url, data):
    ...
Run Code Online (Sandbox Code Playgroud)

是否有可能做到这一点?

python throttling rate-limiting python-3.x python-decorators

4
推荐指数
1
解决办法
1669
查看次数