I have a Flask app that is being run with Tornado:
...some imports
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
...some code
http_server = HTTPServer(WSGIContainer(app))
http_server.listen(5000)
IOLoop.instance().start()
In order to view the app, I go to
http://127.0.0.1:5000
However, I want to be able to send email with the same app:
print "Launch server"
s = smtplib.SMTP(host='127.0.0.1', port='5000')
print "Send mail"
s.sendmail(me, [you], msg.as_string())
s.quit()
When the time comes to send the email, the app just hangs instead of sending the mail. If I do this:
s = smtplib.SMTP('localhost')
I get an error message. Can someone help me out?
Thanks.
UPDATE:
When I use:
s = smtplib.SMTP('localhost')
I get this error message:
ERROR:tornado.application:Uncaught exception, closing connection.
Traceback (most recent call last):
File "/Users/christopherspears/.virtualenvs/traffic/lib/python2.7/site-packages/tornado/iostream.py", line 354, in wrapper
callback(*args)
File "/Users/christopherspears/.virtualenvs/traffic/lib/python2.7/site-packages/tornado/stack_context.py", line 331, in wrapped
raise_exc_info(exc)
File "/Users/christopherspears/.virtualenvs/traffic/lib/python2.7/site-packages/tornado/stack_context.py", line 302, in wrapped
ret = fn(*args, **kwargs)
File "/Users/christopherspears/.virtualenvs/traffic/lib/python2.7/site-packages/tornado/httpserver.py", line 328, in _on_headers
self.request_callback(self._request)
File "/Users/christopherspears/.virtualenvs/traffic/lib/python2.7/site-packages/tornado/wsgi.py", line 253, in __call__
response.extend(app_response)
File "/Users/christopherspears/.virtualenvs/traffic/lib/python2.7/site-packages/werkzeug/wsgi.py", line 682, in __next__
return self._next()
File "/Users/christopherspears/.virtualenvs/traffic/lib/python2.7/site-packages/werkzeug/wrappers.py", line 81, in _iter_encoded
for item in iterable:
File "traffic.py", line 157, in event_stream
detect_spike(row, threshold, me, you)
File "traffic.py", line 132, in detect_spike
s = smtplib.SMTP('localhost')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 250, in __init__
(code, msg) = self.connect(host, port)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 310, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 285, in _get_socket
return socket.create_connection((host, port), timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 571, in create_connection
raise err
error: [Errno 61] Connection refused
Maybe tornado and smtp are not playing nice?