-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/shceduler/job Error:Object of type APScheduler is not JSON serializable #141
Comments
Why not use the builtin scheduler API? Admittedly, I'm having similar issues with the builtin API, will investigate it later. |
You cannot pass the |
I've started using flask-apscheduler for a project and have encountered the same problem. My jobs have various objects passed to them that are not JSON serialisable and cannot be easily made so. The jobs all run without any problems. However, I cannot see what jobs are currently scheduled from the API due to this error occurring. I have no interest in seeing the argument values passed through to the jobs from the API - only which ids are currently scheduled, and when they are scheduled to run. Is it possible to have an option to display a less verbose set of details on the jobs from the API to avoid the need to JSON serialise the arguments? |
I can access http://ipaddr:port/scheduler, but cannot access http://ipaddr:port/scheduler/jobs |
I found the solution myself. It was caused by JSON format. File was json.py that existed in flask_apscheduler package. Commented this return " #return super(JSONEncoder, self).default(obj)". It's ok now. |
When i use the demo from basic example,it worked.
But when i add one job with the args which the initialize scheduler,like this:
@scheduler.task('cron', id='refresh_job', minute='*/1',args=[scheduler]) def refresh_job(scheduler): jobs = scheduler.get_jobs() print(jobs)
the job worked,and when i use Postman,i got an Error
this is Error Message in server
[2021-02-24 19:09:51,219] ERROR in app: Exception on /scheduler/jobs [GET] Traceback (most recent call last): File "/Users/goshoho/anaconda3/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/Users/goshoho/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/Users/goshoho/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Users/goshoho/anaconda3/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise raise value File "/Users/goshoho/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/Users/goshoho/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/Users/goshoho/anaconda3/lib/python3.8/site-packages/flask_apscheduler/scheduler.py", line 373, in decorated return view_func(*args, **kwargs) File "/Users/goshoho/anaconda3/lib/python3.8/site-packages/flask_apscheduler/api.py", line 82, in get_jobs return jsonify(job_states) File "/Users/goshoho/anaconda3/lib/python3.8/site-packages/flask_apscheduler/json.py", line 23, in jsonify return flask.current_app.response_class(dumps(data, indent=indent), status=status, mimetype='application/json') File "/Users/goshoho/anaconda3/lib/python3.8/site-packages/flask_apscheduler/json.py", line 16, in dumps return json.dumps(obj, indent=indent, cls=JSONEncoder) File "/Users/goshoho/anaconda3/lib/python3.8/json/__init__.py", line 234, in dumps return cls( File "/Users/goshoho/anaconda3/lib/python3.8/json/encoder.py", line 199, in encode chunks = self.iterencode(o, _one_shot=True) File "/Users/goshoho/anaconda3/lib/python3.8/json/encoder.py", line 257, in iterencode return _iterencode(o, 0) File "/Users/goshoho/anaconda3/lib/python3.8/site-packages/flask_apscheduler/json.py", line 34, in default return super(JSONEncoder, self).default(obj) File "/Users/goshoho/anaconda3/lib/python3.8/json/encoder.py", line 179, in default raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type APScheduler is not JSON serializable 127.0.0.1 - - [24/Feb/2021 19:09:51] "GET /scheduler/jobs HTTP/1.1" 500 -
May be the sheduler can't be serializable?
i just want cyclical refresh my job list with timing,if there have another solution,it's also grate for me!
The text was updated successfully, but these errors were encountered: