简体   繁体   English

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

[英]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.

相关问题 Airflow SQLCheckOperator 中的错误 - AttributeError: 'NoneType' object 没有属性 'upper' - Error in Airflow SQLCheckOperator - AttributeError: 'NoneType' object has no attribute 'upper' Python AttributeError:'module'对象没有属性'DIST_L2' - Python AttributeError: 'module' object has no attribute 'DIST_L2' Python/Airflow AttributeError:“AwsLambdaHook”对象没有属性“update_relative” - Python/Airflow AttributeError: 'AwsLambdaHook' object has no attribute 'update_relative' 熊猫的气流错误:AttributeError:'Pendulum'对象没有属性'nanosecond' - Airflow error with pandas: AttributeError: 'Pendulum' object has no attribute 'nanosecond' Python“AttributeError:'NoneType'对象没有属性”错误 - Python "AttributeError: 'NoneType' object has no attribute" Error python错误 - attributeError:'str'对象没有属性 - python error - attributeError: 'str' object has no attribute Python错误:AttributeError:'module'对象没有属性 - Python error: AttributeError: 'module' object has no attribute AttributeError: object 没有属性 Python 错误 - AttributeError: object has no attribute Python Error Python属性错误:AttributeError:'str'对象没有属性'to_csv' - Python attribute error: AttributeError: 'str' object has no attribute 'to_csv' Python AttributeError: Object 没有属性 - Python AttributeError: Object has no attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM