flask_limit 限制请求次数时报错TypeError: __init__() got multiple values for argument 'key_func'

代码如下:

from flask import Flask
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address

app = Flask(__name__)

limiter = Limiter(app, key_func=get_remote_address, default_limits=["20000 per day", "50 per hour"])

@app.route('/')
def hello_world():
    return 'Hello World'

if __name__ == '__main__':
    app.run(host="0.0.0.0")

运行报错:TypeError: init() got multiple values for argument 'key_func'
明明之前这么写没有问题的, 去看看源码:

flask_limiter/extension.py

发现flask_limiter新版本key_func参数关键字写到最前面了,所以改一下实例化代码为:

limiter = Limiter(app=app, key_func=get_remote_address, default_limits=["20000 per day", "50 per hour"])
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 系列其他内容docker快速创建轻量级的可移植的容器[https://zhuanlan.zhihu.com/p/4...
    nlper_wx阅读 262评论 0 0
  • Overview The ccxt library is a collection of available cr...
    郭蝈儿蝈儿阅读 3,810评论 0 1
  • 本文首发于:行者AI[https://xingzheai.cn/details/ec49479bc9c] 速率限制...
    行者AI阅读 2,450评论 0 0
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,009评论 19 139
  • Table of Contents WSGIwsgi服务器作用wsgirefhttp协议无状态,短连接,长连接co...
    四月天_da7e阅读 473评论 0 0