2

I'm with a very very wierd bug...

I have a flask app using flask-mail to send email messages.

In a RedHat Server, I tryied using runserver (flask-manager) and gunicorn. So I have a apache server connecting to this app using Proxy.

When I run the app, using any user (root or other), the app runs and it sends emails normally.

But when i close the session with the server (exit in terminal) it stops to send mail and gives me this stack trace:

    in send_mail
    return mail.send(msg)
  File "/usr/local/lib/python2.7/site-packages/flask_mail.py", line 415, in send
    with self.connect() as connection:
  File "/usr/local/lib/python2.7/site-packages/flask_mail.py", line 123, in __enter__
    self.host = self.configure_host()
  File "/usr/local/lib/python2.7/site-packages/flask_mail.py", line 144, in configure_host
    host.login(self.mail.username, self.mail.password)
  File "/usr/local/lib/python2.7/smtplib.py", line 575, in login
    self.ehlo_or_helo_if_needed()
  File "/usr/local/lib/python2.7/smtplib.py", line 535, in ehlo_or_helo_if_needed
    if not (200 <= self.ehlo()[0] <= 299):
  File "/usr/local/lib/python2.7/smtplib.py", line 406, in ehlo
    self.putcmd(self.ehlo_msg, name or self.local_hostname)
  File "/usr/local/lib/python2.7/smtplib.py", line 336, in putcmd
    self.send(str)
  File "/usr/local/lib/python2.7/smtplib.py", line 320, in send
    print>>stderr, 'send:', repr(str)
IOError: [Errno 5] Input/output error

Running with manager:

  • python myapp.py

Running with gunicorn I use:

  • gunicorn -w 2 -b 0.0.0.0:8388 myapp:app

I'm really stuck here.. as i tested using 2 different containers... i do not have any other ideias to solve it... using wsgi i could not make it work on this server cause the lib do not install at all =(

any other ideas?

thanks!

mariomol
  • 667
  • 1
  • 7
  • 15

1 Answers1

1

Looking at smtplib source (https://hg.python.org/cpython/file/2.7/Lib/smtplib.py#l324), it looks like what's happening is you're trying to write to stderr, which may be the source of the I/O error when running under a server.

If you're setting SMTP(...).debuglevel anywhere, try removing that line.

Demian Brecht
  • 21,135
  • 5
  • 42
  • 46
  • I didn't check this line... actually at the first moment i couldnt find.. but you are 100% correct!! Someone in my project added the DEBUG level for all flask app.. so it affected the debug level for smtplib as well.. when I disabled the debug it worked like a charm!! Thanks a lot! – mariomol Nov 01 '15 at 09:19
  • before that.. i changed my flask app to suport python 2.6 and make work wsgi with apache.. using this i could send email even with DEBUG set on.. maybe cause apache get the stderr and send it to log – mariomol Nov 01 '15 at 09:22