librelist archives

« back to archive

Problem with Flask-Mail when used with Gunicorn only

Problem with Flask-Mail when used with Gunicorn only

From:
Anthony Ford
Date:
2013-01-13 @ 06:45
Hey all, I'm running into an issue using Flask-Mail that I cannot resolve.

The issue only occurs when I'm using Gunicorn on Heroku. If I'm running
from within the Flask test server, then the it works perfectly.

The trace I'm getting is below:

         2013-01-13 06:27:19,767 ERROR: Exception on
/admin/mailer/confirmation/sponsor/1073 [GET]
         [in
/app/.heroku/python/lib/python2.7/site-packages/flask/app.py:1210]


 Traceback (most recent call last):
   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py",
line 1504, in wsgi_app
     response = self.full_dispatch_request()
   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py",
line 1264, in full_dispatch_request
     rv = self.handle_user_exception(e)
   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py",
line 1262, in full_dispatch_request
     rv = self.dispatch_request()
   File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py",
line 1248, in dispatch_request
     return self.view_functions[rule.endpoint](**req.view_args)
   File "/app/.heroku/python/lib/python2.7/site-packages/flask_login.py",
line 496, in decorated_view
     return fn(*args, **kwargs)
   File "/app/RGVRSEF/admin/__init__.py", line 439, in sponsorconf
     utils.sponsor_mail(sponsor)
   File "/app/RGVRSEF/utils.py", line 125, in sponsor_mail
     mail.send(conf_email)
   File "/app/.heroku/python/lib/python2.7/site-packages/flask_mail.py",
line 416, in send
     with self.connect() as connection:
   File "/app/.heroku/python/lib/python2.7/site-packages/flask_mail.py",
line 47, in __enter__
     self.host = self.configure_host()
   File "/app/.heroku/python/lib/python2.7/site-packages/flask_mail.py",
line 63, in configure_host
     host = smtplib.SMTP(self.mail.server, self.mail.port)
   File "/app/.heroku/python/lib/python2.7/smtplib.py", line 249, in
__init__
     (code, msg) = self.connect(host, port)
   File "/app/.heroku/python/lib/python2.7/smtplib.py", line 309, in connect
     self.sock = self._get_socket(host, port, self.timeout)
   File "/app/.heroku/python/lib/python2.7/smtplib.py", line 284, in
_get_socket
     return socket.create_connection((port, host), timeout)
   File "/app/.heroku/python/lib/python2.7/site-packages/gevent/socket.py",
line 637, in create_connection
     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
   File "/app/.heroku/python/lib/python2.7/site-packages/gevent/socket.py",
line 737, in getaddrinfo
     raise gaierror(EAI_SERVICE, 'Servname not supported for ai_socktype')
 gaierror: [Errno -8] Servname not supported for ai_socktype
2

Does anybody recognize this error?

Anthony Ford,
KF5IBN,
Research Assistant,
Center for Advanced Radio Astronomy,
University of Texas at Brownsville
ford.anthonyj@gmail.com

Re: Problem with Flask-Mail when used with Gunicorn only

From:
Anthony Ford
Date:
2013-01-13 @ 06:54
Ok, nevermind. I got ahead of myself. I have been trying to debug various
issues from this part of the app for almost two days (It was an old
ep.ioapp that I'm now porting to Heroku), and I wasn't diligent enough
in
googling the traceback.

It turns out the issue stems from the port variable being set by
os.environ, which defaults to string type, and I didn't cast to int.
Solution was found here:

http://stackoverflow.com/questions/7071597/cant-connect-to-smtp-server-with-django-when-using-gevent-socket-py

Hope this helps anyone else who may run into the same problem.

Sorry for the email traffic.

Anthony Ford,
KF5IBN,
Research Assistant,
Center for Advanced Radio Astronomy,
University of Texas at Brownsville
ford.anthonyj@gmail.com


On Sun, Jan 13, 2013 at 12:45 AM, Anthony Ford <ford.anthonyj@gmail.com>wrote:

> Hey all, I'm running into an issue using Flask-Mail that I cannot resolve.
>
> The issue only occurs when I'm using Gunicorn on Heroku. If I'm running
> from within the Flask test server, then the it works perfectly.
>
> The trace I'm getting is below:
>
>          2013-01-13 06:27:19,767 ERROR: Exception on
> /admin/mailer/confirmation/sponsor/1073 [GET]
>          [in
> /app/.heroku/python/lib/python2.7/site-packages/flask/app.py:1210]
>
>
>  Traceback (most recent call last):
>    File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py",
> line 1504, in wsgi_app
>      response = self.full_dispatch_request()
>    File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py",
> line 1264, in full_dispatch_request
>      rv = self.handle_user_exception(e)
>    File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py",
> line 1262, in full_dispatch_request
>      rv = self.dispatch_request()
>    File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py",
> line 1248, in dispatch_request
>      return self.view_functions[rule.endpoint](**req.view_args)
>    File "/app/.heroku/python/lib/python2.7/site-packages/flask_login.py",
> line 496, in decorated_view
>      return fn(*args, **kwargs)
>    File "/app/RGVRSEF/admin/__init__.py", line 439, in sponsorconf
>      utils.sponsor_mail(sponsor)
>    File "/app/RGVRSEF/utils.py", line 125, in sponsor_mail
>      mail.send(conf_email)
>    File "/app/.heroku/python/lib/python2.7/site-packages/flask_mail.py",
> line 416, in send
>      with self.connect() as connection:
>    File "/app/.heroku/python/lib/python2.7/site-packages/flask_mail.py",
> line 47, in __enter__
>      self.host = self.configure_host()
>    File "/app/.heroku/python/lib/python2.7/site-packages/flask_mail.py",
> line 63, in configure_host
>      host = smtplib.SMTP(self.mail.server, self.mail.port)
>    File "/app/.heroku/python/lib/python2.7/smtplib.py", line 249, in
> __init__
>      (code, msg) = self.connect(host, port)
>    File "/app/.heroku/python/lib/python2.7/smtplib.py", line 309, in
> connect
>      self.sock = self._get_socket(host, port, self.timeout)
>    File "/app/.heroku/python/lib/python2.7/smtplib.py", line 284, in
> _get_socket
>      return socket.create_connection((port, host), timeout)
>    File
> "/app/.heroku/python/lib/python2.7/site-packages/gevent/socket.py", line
> 637, in create_connection
>      for res in getaddrinfo(host, port, 0, SOCK_STREAM):
>    File
> "/app/.heroku/python/lib/python2.7/site-packages/gevent/socket.py", line
> 737, in getaddrinfo
>      raise gaierror(EAI_SERVICE, 'Servname not supported for ai_socktype')
>  gaierror: [Errno -8] Servname not supported for ai_socktype
> 2
>
> Does anybody recognize this error?
>
> Anthony Ford,
> KF5IBN,
> Research Assistant,
> Center for Advanced Radio Astronomy,
> University of Texas at Brownsville
> ford.anthonyj@gmail.com
>