python - AttributeError: 'datetime.timezone' 对象在尝试运行 Apache Airflow 调度程序时没有属性'name'
问题描述
我刚刚设置了一台新的 Ubuntu 机器,创建了一个 Python3.6 venv 并安装了气流。我可以启动网络服务器,但是当我尝试运行时,airflow scheduler
我不断收到此错误:
File "/home/ubuntu/venv/airflow/lib/python3.6/site-packages/airflow/models/dag.py", line 398, in following_schedule
tz = pendulum.timezone(self.timezone.name)
AttributeError: 'datetime.timezone' object has no attribute 'name'
这是我的摘录pip freeze
:
apache-airflow==1.10.5
boto3==1.9.253
Pillow==6.2.1
selenium==3.141.0
slackclient==1.2.1
解决方案
datetime.datetime
您使用的对象tzinfo
具有无name
属性。例如,如果您使用datetime.timezone.utc
该实现没有name
属性。
from datetime import datetime,timezone,timedelta
dag = DAG(
dag_id="xxxx",
default_args=args,
start_date=datetime(2021, 5, 31, tzinfo=timezone.utc, # will raise AttributeError later
schedule_interval="0 8 * * *",
max_active_runs=1,
dagrun_timeout=timedelta(minutes=60),
catchup=False,
description="xx",
)
因此,您需要提供另一个时区对象,例如 pendulum 包 ( tzinfo=pendulum.timezone("UTC")
) 提供的时区对象。
import pendulum
from datetime import datetime,timedelta
dag = DAG(
dag_id="xxxx",
start_date=datetime(2021, 5, 31, tzinfo=pendulum.timezone("UTC"),
...
)
我向气流项目提交了一个问题,以便在此处为这种特殊情况提供更好的错误消息
推荐阅读
- haskell - 为 Maybe 数据类型定义 Ord 实例
- tsql - 检索给定用户开始和结束期间日期的最新更改
- ruby - 我需要我的 Jekyll 生成器插件一个接一个地运行,但另一个需要最后的优先级
- php - 在 Laravel Blade 中访问多维数组值
- c++ - 为什么 Clang 为引用和非空指针参数生成不同的代码?
- objective-c - 在 AppKit 中初始化选定的单选按钮 (NSButton) 组
- python - Pytesseract 图像到字符串问题
- python - 无法导入 main.py 中所需的 python 文件
- mongodb - 如何在快速路由器中使用 Mongoose 查找查询?
- python - 我如何使用 discord py 在特定频道中固定具有特定角色的用户的图像