Flask-security: AttributeError: 'NoneType' object has no attribute 'send'

Created on 20 Oct 2012  路  5Comments  路  Source: mattupstate/flask-security

I get this error while trying to register an user:

AttributeError: 'NoneType' object has no attribute 'send'

File "/Users/g/myapp/lib/python2.7/site-packages/flask/app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/g/myapp/lib/python2.7/site-packages/flask/app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/g/myapp/lib/python2.7/site-packages/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/Users/g/myapp/lib/python2.7/site-packages/flask/app.py", line 1360, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/g/myapp/lib/python2.7/site-packages/flask/app.py", line 1358, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/g/myapp/lib/python2.7/site-packages/flask/app.py", line 1344, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/g/myapp/lib/python2.7/site-packages/flask_security/views.py", line 113, in register
user = register_user(**form.to_dict())
File "/Users/g/myapp/lib/python2.7/site-packages/flask_security/registerable.py", line 39, in register_user
user=user, confirmation_link=confirmation_link)
File "/Users/g/myapp/lib/python2.7/site-packages/flask_security/utils.py", line 235, in send_mail
mail.send(msg)

I am using Python 2.7.3, Flask 0.9, Flask-Security 1.5.0 and Flask-Mail 0.7.3

Most helpful comment

Looks like you have to initialize the Mail object yourself:

mail = Mail()
app = Flask(__name__)
mail.init_app(app)

(from https://pythonhosted.org/Flask-Mail/)

This makes sense because Flask-Security lists all features that use Flask-Mail as optional

All 5 comments

From the interactive debugger:

[console ready]
>>> current_app
<LocalProxy unbound>
>>> current_app.extensions.get('mail')
Traceback (most recent call last):

File "<debugger>", line 1, in <module>
current_app.extensions.get('mail')
File "/Users/g/myapp/lib/python2.7/site-packages/werkzeug/local.py", line 336, in __getattr__
return getattr(self._get_current_object(), name)
File "/Users/g/myapp/lib/python2.7/site-packages/werkzeug/local.py", line 295, in _get_current_object
return self.__local()
File "/Users/g/myapp/lib/python2.7/site-packages/flask/globals.py", line 26, in _find_app
raise RuntimeError('working outside of application context')
RuntimeError: working outside of application context

I believe this is because you haven't created and configured the Flask-Mail extension. I need to make the documentation clearer that you need to do this yourself. Take a look at the test app to see what to do:

https://github.com/mattupstate/flask-security/blob/develop/tests/test_app/__init__.py

Solved thanks!
I configured Mail just trough the config keys I thought flask-security was initializing it for me.

The link is no longer available can someone please help me on how to fix this issue ?

Looks like you have to initialize the Mail object yourself:

mail = Mail()
app = Flask(__name__)
mail.init_app(app)

(from https://pythonhosted.org/Flask-Mail/)

This makes sense because Flask-Security lists all features that use Flask-Mail as optional

Was this page helpful?
0 / 5 - 0 ratings

Related issues

asmodehn picture asmodehn  路  4Comments

williamcheng-web picture williamcheng-web  路  4Comments

asmodehn picture asmodehn  路  6Comments

ochronus picture ochronus  路  4Comments

DerekDomino picture DerekDomino  路  5Comments