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

2024-09-19 20:51:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我是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

以及我使用传感器的地方

^{pr2}$

Tags: topathselfinitdefcount错误args
1条回答
网友
1楼 · 发布于 2024-09-19 20:51:15

我和一个气流操作员也遇到了类似的错误:

AttributeError: 'MyOperator' object has no attribute 't'

要解决此问题,请检查template_fields与您的__init__参数相比是否有意义。在

您有template_fields = "previous_month",但在您的__init__中没有这样的参数。在

在我的例子中,__init__和{}确实对齐。但是,我用了template_fields = ("myfield")而不是{}。逗号必须存在。在

相关问题 更多 >