代码如下:
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新版本key_func参数关键字写到最前面了,所以改一下实例化代码为:
limiter = Limiter(app=app, key_func=get_remote_address, default_limits=["20000 per day", "50 per hour"])