PytzUsageWarning: The normalize method is no longer necessary

PytzUsageWarning: The normalize method is no longer necessary

在Python中使用apscheduler进行定时任务,启动定时脚本时抛出错误PytzUsageWarning: The normalize method is no longer necessary

原代码

from apscheduler.schedulers.blocking import BlockingScheduler


def crawler():
	"""爬虫任务"""
	pass


def main():
    """主函数"""
    # 创建定时对象
    scheduler = BlockingScheduler()

    # 定义任务
    scheduler.add_job(crawler, 'cron', day_of_week='tue', hour=8, minute=00)

    # 启动任务
    print("+++ +++ +++ 启动 +++ +++ +++")
    scheduler.start()


if __name__ == '__main__':
    main()

**

执行报错

C:\SmartTV>python SmartTv.py
C:\Users\yang\AppData\Local\Programs\Python\Python310\lib\site-packages\apscheduler\util.py:95: PytzUsageWarning: The zone attribute is specific to pytz's interface; please migrate to a new time zone provider. For more details on how to do so, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
  if obj.zone == 'local':
+++ +++ +++ 启动 +++ +++ +++
C:\Users\yang\AppData\Local\Programs\Python\Python310\lib\site-packages\apscheduler\triggers\cron\__init__.py:146: PytzUsageWarning: The normalize method is no longer necessary, as this time zone supports the fold attribute (PEP 495). For more details on migrating to a PEP 495-compliant implementation, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
  return self.timezone.normalize(dateval + difference), fieldnum
C:\Users\yang\AppData\Local\Programs\Python\Python310\lib\site-packages\apscheduler\triggers\cron\__init__.py:159: PytzUsageWarning: The localize method is no longer necessary, as this time zone supports the fold attribute (PEP 495). For more details on migrating to a PEP 495-compliant implementation, see https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
  return self.timezone.localize(datetime(**values))

修改之后的代码

from apscheduler.schedulers.blocking import BlockingScheduler


def crawler():
	"""爬虫任务"""
	pass


def main():
    """主函数"""
    
    # 创建定时对象
    scheduler = BlockingScheduler(timezone="Asia/Shanghai")

    # 定义任务
    scheduler.add_job(crawler, 'cron', day_of_week='tue', hour=8, minute=00)

    # 启动任务
    print("+++ +++ +++ 启动 +++ +++ +++")
    scheduler.start()


if __name__ == '__main__':
    main()
  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值