gpt4 book ai didi

python - Django REST 如何设置 throttle 时间以允许 10 分钟内发出一个请求?

转载 作者:太空宇宙 更新时间:2023-11-04 04:42:21 25 4
gpt4 key购买 nike

文档说该期间应该是以下之一:('s', 'sec', 'm', 'min', 'h', 'hour', 'd', 'day')。我很好奇是否可以将周期设置为类似 1/10min 的值?

最佳答案

查看 codedocumentation你不能“开箱即用”。但我确实看到了制造你自己的可能性 custom throttle基于现有的一个:

from rest_framework.throttling import AnonRateThrottle


class AnonTenPerTenMinutesThrottle(AnonRateThrottle):
def parse_rate(self, rate):
"""
Given the request rate string, return a two tuple of:
<allowed number of requests>, <period of time in seconds>

So we always return a rate for 10 request per 10 minutes.

Args:
string: rate to be parsed, which we ignore.

Returns:
tuple: <allowed number of requests>, <period of time in seconds>
"""
return (10, 600)

关于python - Django REST 如何设置 throttle 时间以允许 10 分钟内发出一个请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50370544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com