Skip to content

smtplib ssl authentication fails passing a Unicode password in 1.7.0 #1433

@tmkdev

Description

@tmkdev

Dear Airflow Maintainers,

Environment

Before I tell you about my issue, let me describe my Airflow environment:

Please fill out any appropriate fields:

  • Airflow version: 1.7.0
  • Airflow components:smtp mailer
  • Relevant airflow.cfg settings:
  • Python Version:2.7.11+
  • Operating System: Ubuntu Mate 16.04

Description of Issue

smtplib ssl authentication fails passing a Unicode password.

[2016-04-26 10:29:28,775] {models.py:1128} ERROR - Failed to send email to: ['xxxxxx@xxxxx.com']
[2016-04-26 10:29:28,775] {models.py:1129} ERROR - 'in ' requires string as left operand, not int
Traceback (most recent call last):
File "/opt/airflow/local/lib/python2.7/site-packages/airflow/models.py", line 1125, in handle_failure
self.email_alert(error, is_retry=False)
File "/opt/airflow/local/lib/python2.7/site-packages/airflow/models.py", line 1242, in email_alert
utils.send_email(task.email, title, body)
File "/opt/airflow/local/lib/python2.7/site-packages/airflow/utils.py", line 504, in send_email
return backend(to, subject, html_content, files=files, dryrun=dryrun)
File "/opt/airflow/local/lib/python2.7/site-packages/airflow/utils.py", line 539, in send_email_smtp
send_MIME_email(SMTP_MAIL_FROM, to, msg, dryrun)
File "/opt/airflow/local/lib/python2.7/site-packages/airflow/utils.py", line 555, in send_MIME_email
s.login(SMTP_USER, SMTP_PASSWORD)
File "/usr/lib/python2.7/smtplib.py", line 607, in login
(code, resp) = self.docmd(encode_cram_md5(resp, user, password))
File "/usr/lib/python2.7/smtplib.py", line 571, in encode_cram_md5
response = user + " " + hmac.HMAC(password, challenge).hexdigest()
File "/usr/lib/python2.7/hmac.py", line 75, in init
self.outer.update(key.translate(trans_5C))
File "/opt/airflow/local/lib/python2.7/site-packages/future/types/newstr.py", line 390, in translate
if ord(c) in table:
TypeError: 'in ' requires string as left operand, not int

I can get it to work with this hack in utils.send_MIME_email.

def send_MIME_email(e_from, e_to, mime_msg, dryrun=False):
SMTP_HOST = configuration.get('smtp', 'SMTP_HOST')
SMTP_PORT = configuration.getint('smtp', 'SMTP_PORT')
SMTP_USER = configuration.get('smtp', 'SMTP_USER').encode('ascii','ignore')
SMTP_PASSWORD = configuration.get('smtp', 'SMTP_PASSWORD').encode('ascii','ignore')
SMTP_STARTTLS = configuration.getboolean('smtp', 'SMTP_STARTTLS')
SMTP_SSL = configuration.getboolean('smtp', 'SMTP_SSL')

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:bugThis is a clearly a bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions