[英]Python airflow error AttributeError: 'xsensor' object has no attribute 'l'
I am new to Python and airflow.我是 Python 和气流的新手。 Trying to implement a sensor as below, and the error says "AttributeError: 'mySensor' object has no attribute 'l'" I had a look at other attribute error questions, but I have no idea where the 'l' in my error comes from.
尝试实现如下传感器,错误显示“AttributeError: 'mySensor' object has no attribute 'l'”我查看了其他属性错误问题,但我不知道错误中的 'l' 在哪里从。 Could someone help shed some light on this?
有人可以帮助阐明这一点吗? Below is the whole class for mySensor.
下面是 mySensor 的整个类。 Many thanks.
非常感谢。
class mySensor(SFTPSensor):
"""
Subclass of SFTPSensor to override the poke() method
"""
template_fields = "previous_month"
@apply_defaults
def __init__(self,
last_day_previous_month,
*args,
**kwargs):
self.previous_month = previous_month
super(mySensor, self).__init__(*args, **kwargs)
def poke(self, context):
remote_path = self.path+"file_to_check"+self.previous_month
file_count = len(self.hook.list_directory(remote_path))
if file_count == 0:
return False
else:
logging.info("Found %d files", file_count)
return True
and where I used the Sensor以及我使用传感器的地方
sensor_task = mySensor(
previous_month=_previous_month_template,
task_id="check-remote-files",
dag=dag,
sftp_conn_id=my_conn_id,
path="/my/path/"
)
I was getting a similar error with an Airflow operator:我在使用 Airflow 操作员时遇到了类似的错误:
AttributeError: 'MyOperator' object has no attribute 't'
AttributeError: 'MyOperator' 对象没有属性 't'
To resolve, check that the template_fields
makes sense compared to your __init__
arguments.要解决,请检查
template_fields
与您的__init__
参数相比是否有意义。
You have template_fields = "previous_month"
but in your __init__
there is no such parameter.您有
template_fields = "previous_month"
但在您的__init__
中没有这样的参数。
In my case, the __init__
and template_fields
did align.就我而言,
__init__
和template_fields
确实对齐。 However, I had template_fields = ("myfield")
instead of template_fields = ("myfield",)
.但是,我有
template_fields = ("myfield")
而不是template_fields = ("myfield",)
。 The comma must be present.逗号必须存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.