程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Exception handling of time zone thrown during Python flask startup

編輯:Python

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")


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved