[Python]apscheduler出现Unable to determine the name of the local timezone 可能解决方法

注意!我遇到的问题,可能并不是你遇到的问题,但是本文可能给你以解决问题的一个思路。

我在使用apscheduler作为python任务调度。后来,我发现时间不对劲,快了俩小时。于是就调整了一下时间。使用方法如下

rm -rf /etc/timezone
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

简单粗暴不是么?用ntp同步了时间之后,正常了。

但是当我再次调用apscheduler的时候发现,无法调度,并且爆了下面这个错误

ValueError: Unable to determine the name of the local timezone -- you must explicitly specify the name of the local timezone. Please refrain from using timezones like EST to prevent problems with daylight saving time. Instead, use a locale based timezone name (such as Europe/Helsinki).

这tmd就蛋疼了。所以,我就装了个tzlocal,用get_localzone 这个方法来打印自己机器的timezone,这一打印,发现结果就很奇怪,系统显示的是正常的Asia/Shanghai 但是,python获取的却是local?
不过,这没关系,我们去谷歌一下正规的修改timezone的方法:

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 如果你是CentOS7就更简单了,单单执行下面命令就OK了
timedatectl set-timezone Asia/Shanghai

修改后,成功运行。
时候总结:可能timezone文件依赖了一些文件,然后这些文件的路径是相对路径,因此就出现了直接复制之后,某些文件无法找到的问题,造成了python获取timezone失败。而timezone文件本身又包含了系统能用的信息,因此系统又能自动识别。

未经允许不得转载:RffanLAB|Rffan实验室 » [Python]apscheduler出现Unable to determine the name of the local timezone 可能解决方法

赞 (3) 打赏

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏