Joseph Harris created AIRFLOW-835: ------------------------------------- Summary: SMTP Mail delivery fails with server using CRAM-MD5 auth Key: AIRFLOW-835 URL: https://issues.apache.org/jira/browse/AIRFLOW-835 Project: Apache Airflow Issue Type: Bug Components: utils Affects Versions: Airflow 1.7.1 Environment: https://hub.docker.com/_/python/ (debian:jessie + python2.7 in docker) Reporter: Joseph Harris Priority: Minor
Traceback when sending email from smtp-server configured to offer CRAM-MD5 (in all cases, tls included). This occurs because the configuration module returns the password as a futures.types.newstr, instead of a plain str (see below for gory details of why this breaks). Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/airflow/models.py", line 1308, in handle_failure self.email_alert(error, is_retry=False) File "/usr/local/lib/python2.7/site-packages/airflow/models.py", line 1425, in email_alert send_email(task.email, title, body) File "/usr/local/lib/python2.7/site-packages/airflow/utils/email.py", line 43, in send_email return backend(to, subject, html_content, files=files, dryrun=dryrun) File "/usr/local/lib/python2.7/site-packages/airflow/utils/email.py", line 79, in send_email_smtp send_MIME_email(SMTP_MAIL_FROM, to, msg, dryrun) File "/usr/local/lib/python2.7/site-packages/airflow/utils/email.py", line 95, in send_MIME_email s.login(SMTP_USER, SMTP_PASSWORD) File "/usr/local/lib/python2.7/smtplib.py", line 607, in login (code, resp) = self.docmd(encode_cram_md5(resp, user, password)) File "/usr/local/lib/python2.7/smtplib.py", line 571, in encode_cram_md5 response = user + " " + hmac.HMAC(password, challenge).hexdigest() File "/usr/local/lib/python2.7/hmac.py", line 75, in __init__ self.outer.update(key.translate(trans_5C)) File "/usr/local/lib/python2.7/site-packages/future/types/newstr.py", line 390, in translate if ord(c) in table: TypeError: 'in <string>' requires string as left operand, not int SMTP configs: [email] email_backend = airflow.utils.email.send_email_smtp [smtp] smtp_host = {a_smtp_server} smtp_port = 587 smtp_starttls = True smtp_ssl = False smtp_user = {a_username} smtp_password = {a_password} smtp_mail_from = {a_email_addr} *Gory details If the server offers CRAM-MD5, smptlib prefers this by default, and will try to use hmac.HMAC to hash the password: https://hg.python.org/cpython/file/2.7/Lib/smtplib.py#l602 https://hg.python.org/cpython/file/2.7/Lib/smtplib.py#l571 But if the password is a newstr, newstr.translate expects a dict mapping instead of str, and raises an exception. https://hg.python.org/cpython/file/2.7/Lib/hmac.py#l75 All of this occurs after a successful SMTP.ehlo(), so it's probably not crap container networking Could be resolved by passing the smtp password as a futures.types.newbytes, as this behaves as expected: from future.types import newstr, newbytes import hmac # Make str / newstr types test = 'a_string' test_newstr = newstr(test) test_newbytes = newbytes(test) msg = 'future problems' # Test 1 - Try to do a HMAC: # fine hmac.HMAC(test, msg) # fails horribly hmac.HMAC(test_newstr, msg) # is completely fine hmac.HMAC(test_newbytes, msg) -- This message was sent by Atlassian JIRA (v6.3.15#6346)