Python气流错误AttributeError:'xsensor'对象没有属性'l'

use*_*606 0 python attributes airflow

我是 Python 和气流的新手。尝试实现如下传感器,错误显示“AttributeError: 'mySensor' object has no attribute 'l'”我查看了其他属性错误问题,但我不知道错误中的 'l' 在哪里从。有人可以帮助阐明这一点吗?下面是 mySensor 的整个类。非常感谢。

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
Run Code Online (Sandbox Code Playgroud)

以及我使用传感器的地方

sensor_task = mySensor(
                    previous_month=_previous_month_template,
                    task_id="check-remote-files",
                    dag=dag,
                    sftp_conn_id=my_conn_id,
                    path="/my/path/"
                    )
Run Code Online (Sandbox Code Playgroud)

Bjo*_*orn 5

我在使用 Airflow 操作员时遇到了类似的错误:

AttributeError: 'MyOperator' 对象没有属性 't'

要解决,请检查template_fields与您的__init__论点相比是否有意义。

你有template_fields = "previous_month"但在你__init__没有这样的参数。

就我而言,__init__template_fields确实对齐。但是,我有template_fields = ("myfield")而不是template_fields = ("myfield",). 逗号必须存在。