调用电子邮件函数的云作曲家 pythonoperator 因缺少位置参数而失败
cloud composer pythonoperator to call an email function fails with missing positional argument
我有一个 python 运算符来调用一个函数来发送电子邮件,但我收到一个错误
missing 1 required positional argument: contextDict
def send_email(contextDict, **kwargs):
"""Send custom email alerts."""
# email title.
title = "THIS IS A TEST"+file_name+" Failed"
# email contents
body = """
Hi Everyone, <br>
<br>
This is a test pls ignore .<br>
<br>
"""
send_email('email@domain.com', title, body)
我用以下方式调用它:
PythonOperator(task_id='fail_task',
python_callable=notify_email,
provide_context = True,
dag=dag)
我只是尝试使用分支
根据上游条件发送电子邮件(我不是在寻找任务失败时的电子邮件)
我认为我应该将 op_args
传递给该函数,但我不确定将什么传递给上下文字典,因为它已经具有所需的所有宏、dag 和任务信息。
注意:如果我不传入contextdictionary
,我可以使电子邮件正常工作,但我想获取 dag、任务和其他信息并添加更多我需要上下文字典的逻辑任何建议表示赞赏。
因此您的 pythonOperator 缺少 op_kwargs 以及与所需位置参数相关的键值,它应该如下所示,
PythonOperator(task_id='fail_task',
python_callable=notify_email,
provide_context = True,
op_kwargs={'contextDict': "value"}
dag=dag)
注意:将"value"改为相关的。
如果 contextDict 不是强制性的,则将其从函数中删除,运行它就像你以前做的那样。
我有一个 python 运算符来调用一个函数来发送电子邮件,但我收到一个错误
missing 1 required positional argument:
contextDict
def send_email(contextDict, **kwargs):
"""Send custom email alerts."""
# email title.
title = "THIS IS A TEST"+file_name+" Failed"
# email contents
body = """
Hi Everyone, <br>
<br>
This is a test pls ignore .<br>
<br>
"""
send_email('email@domain.com', title, body)
我用以下方式调用它:
PythonOperator(task_id='fail_task',
python_callable=notify_email,
provide_context = True,
dag=dag)
我只是尝试使用分支
根据上游条件发送电子邮件(我不是在寻找任务失败时的电子邮件)我认为我应该将 op_args
传递给该函数,但我不确定将什么传递给上下文字典,因为它已经具有所需的所有宏、dag 和任务信息。
注意:如果我不传入contextdictionary
,我可以使电子邮件正常工作,但我想获取 dag、任务和其他信息并添加更多我需要上下文字典的逻辑任何建议表示赞赏。
因此您的 pythonOperator 缺少 op_kwargs 以及与所需位置参数相关的键值,它应该如下所示,
PythonOperator(task_id='fail_task',
python_callable=notify_email,
provide_context = True,
op_kwargs={'contextDict': "value"}
dag=dag)
注意:将"value"改为相关的。
如果 contextDict 不是强制性的,则将其从函数中删除,运行它就像你以前做的那样。