python3 flask Framework of the web When the system starts ,APScheduler Throw the following exception
Traceback (most recent call last):
File "/opt/autocheck/run.py", line 2, in <module>
from ops import app
File "/opt/autocheck/ops/__init__.py", line 19, in <module>
scheduler = schedulerJob()
File "/opt/autocheck/ops/task/tasksList.py", line 41, in schedulerJob
scheduler = BackgroundScheduler()
File "/usr/local/lib/python3.10/site-packages/apscheduler/schedulers/base.py", line 87, in __init__
self.configure(gconfig, **options)
File "/usr/local/lib/python3.10/site-packages/apscheduler/schedulers/base.py", line 131, in configure
self._configure(config)
File "/usr/local/lib/python3.10/site-packages/apscheduler/schedulers/background.py", line 29, in _configure
super(BackgroundScheduler, self)._configure(config)
File "/usr/local/lib/python3.10/site-packages/apscheduler/schedulers/base.py", line 701, in _configure
self.timezone = astimezone(config.pop('timezone', None)) or get_localzone()
File "/usr/local/lib/python3.10/site-packages/tzlocal/unix.py", line 203, in get_localzone
_cache_tz = _get_localzone()
File "/usr/local/lib/python3.10/site-packages/tzlocal/unix.py", line 185, in _get_localzone
utils.assert_tz_offset(tz)
File "/usr/local/lib/python3.10/site-packages/tzlocal/utils.py", line 63, in assert_tz_offset
raise ValueError(msg)
ValueError: Timezone offset does not match system offset: 0 != 28800. Please, check your config files.
By analyzing the exception log , Find out APScheduler Default timezone, and “0” Is the of the system environment variable obtained TZ Time 28800 Corresponding timezone by “Asia/Shanghai”, and 0 Corresponding timezone by “UTC”, So we just need to compare the time zone of the system environment variable with APScheduler Set the time zone of to be consistent
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) HUWJ Organization. https://huwen.blog.csdn.net
# Copyright: (c) <[email protected]>
# Released under the AGPL-3.0 License.
from apscheduler.schedulers.background import BackgroundScheduler
import os
os.environ['TZ']= "Asia/Shanghai"
scheduler = BackgroundScheduler(timezone="Asia/Shanghai")