前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[Python]apscheduler出现Unable to determine the name of the local timezone 可能解决方法

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

作者头像
用户2353021
发布2020-05-11 17:46:44
1.5K0
发布2020-05-11 17:46:44
举报
文章被收录于专栏:RFFAN实验室RFFAN实验室

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

我在使用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文件本身又包含了系统能用的信息,因此系统又能自动识别。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-11-29 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档