gpt4 book ai didi

Airflow EmailOperator 抛出 "smtplib.SMTPNotSupportedError: STARTTLS extension not supported by server"?

转载 作者:行者123 更新时间:2023-12-04 17:32:20 46 4
gpt4 key购买 nike

尝试使用 Airflow 的 EmailOperatortrigger_rule.ONE_FAILED 上发送电子邮件并看到错误:

[2019-10-14 13:31:50,604] {configuration.py:206} WARNING - section/key [smtp/smtp_user] not found in config
Traceback (most recent call last):
File "/bin/airflow", line 27, in <module>
[ args.func(args)
File "/usr/lib/python2.7/site-packages/airflow/bin/cli.py", line 392, in run
pool=args.pool,
File "/usr/lib/python2.7/site-packages/airflow/utils/db.py", line 50, in wrapper
result = func(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/airflow/models.py", line 1493, in _run_raw_task
result = task_copy.execute(context=context)
File "/usr/lib/python2.7/site-packages/airflow/operators/email_operator.py", line 64, in execute
send_email(self.to, self.subject, self.html_content, files=self.files, cc=self.cc, bcc=self.bcc, mime_subtype=self.mime_subtype)
File "/usr/lib/python2.7/site-packages/airflow/utils/email.py", line 44, in send_email
return backend(to, subject, html_content, files=files, dryrun=dryrun, cc=cc, bcc=bcc, mime_subtype=mime_subtype)
File "/usr/lib/python2.7/site-packages/airflow/utils/email.py", line 87, in send_email_smtp
send_MIME_email(SMTP_MAIL_FROM, recipients, msg, dryrun)
File "/usr/lib/python2.7/site-packages/airflow/utils/email.py", line 109, in send_MIME_email
s.starttls()
File "/usr/lib64/python2.7/smtplib.py", line 643, in starttls
raise SMTPException("STARTTLS extension not supported by server.")
smtplib.SMTPException: STARTTLS

没有更改默认的airflow.cfg(访问网络服务器的基本密码验证除外)并且电子邮件部分看起来像

[email]
email_backend = airflow.utils.email.send_email_smtp


[smtp]
# If you want airflow to send emails on retries, failure, and you want to use
# the airflow.utils.email.send_email_smtp function, you have to configure an
# smtp server here
smtp_host = localhost
smtp_starttls = True
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
# smtp_user = airflow
# smtp_password = airflow
smtp_port = 25
smtp_mail_from = airflow@example.com

查看cfg文件中的端口,好像是open and listening...

[rvillanueva@mapr001 queensetl_airflow]$ netstat -plnt | grep ':25'
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN -
tcp6 0 0 ::1:25 :::* LISTEN -

...而且我能够对同一台机器 (CentOS 7) 上运行的其他进程使用 linux sendmail bash 命令。

有人知道这里会发生什么或任何进一步的调试提示吗?

最佳答案

在 airflow 用户邮件列表和上面显示的错误跟踪的帮助下,解决这个问题的方法是设置 smtp_starttls = False

使用类似...的脚本进行测试

# Import smtplib for the actual sending function
import smtplib
from email.mime.text import MIMEText

send_to = 'myaddress@co.org'
msg = MIMEText('Hello World')
msg['Subject'] = 'Test Airflow Email'
msg['From'] = 'airflow@example.com'
msg['To'] = send_to

# SMTP Send
s = smtplib.SMTP('localhost')
s.starttls() # Try commenting out this line and see if you get a different error
s.sendmail(me, [send_to], msg.as_string())
s.quit()

看到了同样的错误,并且能够通过注释掉 s.starttls() 行来摆脱它。所以现在我的 airflow.cfg 文件看起来像...

[smtp]
# If you want airflow to send emails on retries, failure, and you want to use
# the airflow.utils.email.send_email_smtp function, you have to configure an
# smtp server here
smtp_host = localhost
#smtp_starttls = True
smtp_starttls = False
smtp_ssl = False
# Uncomment and set the user/pass settings if you want to use SMTP AUTH
# smtp_user = airflow
# smtp_password = airflow
smtp_port = 25
smtp_mail_from = airflow@example.com

并且电子邮件提醒似乎工作正常。

关于 Airflow EmailOperator 抛出 "smtplib.SMTPNotSupportedError: STARTTLS extension not supported by server"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58386075/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com