flask_apscheduler "error_message": "The list of positional arguments is longer than the target callable can handle (allowed: 0, given in args: 6)"

flask_apscheduler "error_message": "The list of positional arguments is longer than the target callable can handle (allowed: 0, given in args: 6)"

需要帮助通过 POST json 将参数传递给 flask-apscheduler,我正在尝试添加作业,它应该 return 并每 2 秒打印一次 testing2。

这是我的 json post 使用 postnam:

{
    "id":"testing2",
    "func":"app:run",
    "args":"(testing2)",
    "trigger":"interval",
    "seconds":5
}

到URL:http://127.0.0.1:5000/scheduler/jobs

这是我的代码:

from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore
from flask import Flask
from flask_apscheduler.utils import trigger_to_dict

from flask_apscheduler import APScheduler

def run(id):
    print(str(id))

class Config:
    SCHEDULER_JOBSTORES = {
        "default": SQLAlchemyJobStore(url="sqlite:///job.db") 
    }

    SCHEDULER_API_ENABLED = True
if __name__ == "__main__":
    app = Flask(__name__)
    app.config.from_object(Config())
    scheduler = APScheduler()
    scheduler.init_app(app)
    scheduler.start()
    app.run()

通过将 args 从“(testing2)”更改为 [“testing”] 解决了问题。

{ “id”:“测试2”, “功能”:“应用程序:运行”, “参数”:[“测试2”], “触发器”:“间隔”, “秒”:5 }