EmailOperator воздушного потока выдает "smtplib.SMTPNotSupportedError: расширение STARTTLS не поддерживается сервером"? - PullRequest
2 голосов
/ 15 октября 2019

Попытка использовать EmailOperator airflow для отправки электронного письма на trigger_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, кажется, что он открыт и прослушивает ...

[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      -  

... и я могуиспользовать команду linux sendmail bash для других процессов, выполняющихся на этой же машине (CentOS 7).

Кто-нибудь знает, что здесь происходит, или какие-либо дополнительные советы по отладке?

1 Ответ

0 голосов
/ 18 октября 2019

После получения справки из списка рассылки пользователей воздушного потока и из трассы ошибок, показанной выше, эта проблема решалась только установкой 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

, и оповещения по электронной почте работают нормально.

...