0

I have setup a flask-security app, but I'm getting an error creating users and resetting passwords.

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1997, in __call__ 
  return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1985, in wsgi_app
  response = self.handle_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1540, in handle_exception
  reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app
  response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1614, in full_dispatch_request
  rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1612, in full_dispatch_request
  rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1598, in dispatch_request
  return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python2.7/dist-packages/flask_securit /decorators.py", line 230, in wrapper
  return f(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flask_security/views.py", line 118, in register
  user = register_user(**form.to_dict())
File "/usr/local/lib/python2.7/dist-packages/flask_security/registerable.py", line 41, in register_user
  'welcome', user=user, confirmation_link=confirmation_link)
File "/usr/local/lib/python2.7/dist-packages/flask_security/utils.py", line 401, in send_mail
  mail.send(msg)
File "/usr/local/lib/python2.7/dist-packages/flask_mail.py", line 492, in send
  message.send(connection)
File "/usr/local/lib/python2.7/dist-packages/flask_mail.py", line 427, in send
  connection.send(self)
File "/usr/local/lib/python2.7/dist-packages/flask_mail.py", line 188, in send
  self.host.sendmail(sanitize_address(envelope_from or message.sender),
File "/usr/local/lib/python2.7/dist-packages/flask_mail.py", line 105, in sanitize_address
  nm, addr = addr

ValueError: too many values to unpack    ValueError: too many values to unpack

I just followed the guide from https://pythonhosted.org/Flask-Security/quickstart.html#basic-sqlalchemy-application

I need help finding out what is wrong.

Here is my e-mail config:

app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_USERNAME'] = 'devskovsted@gmail.com'
app.config['MAIL_PASSWORD'] = '**********'
app.config['MAIL_DEFAULT_SENDER'] = 'devskovsted@gmail.com'
mail = Mail(app)

/Kresten

Kresten
  • 810
  • 13
  • 36
  • 3
    Can you show us which line of the code triggers that error, and which version of Python you are running? – Arne Apr 30 '18 at 17:04
  • I just updated the question with the full error. I'm running with python 2.7. I'll try to opdate to python 3.6 – Kresten Apr 30 '18 at 18:04
  • I did upgrade to python 3.5, but I just got a new error: TypeError: b'918dfe1d793500723996256a8625314f1b4353e1' is not JSON serializable – Kresten Apr 30 '18 at 19:05
  • 1
    try setting the SECURITY_EMAIL_SENDER application setting. The issue tracker has a closed issue that sounds similar: https://github.com/mattupstate/flask-security/issues/685 – Doobeh Apr 30 '18 at 19:21
  • It would also be helpful to know which version of Flask-Security you're running (or any other requirements.txt entries you may have). – Doobeh Apr 30 '18 at 19:22
  • Flask-Login 0.4.1 Flask-Mail 0.9.1 Flask-Principal 0.4.0 Flask-Security 3.0.0 Flask-SQLAlchemy 2.3.2 Flask-WTF 0.14.2 itsdangerous 0.24 Jinja2 2.10 MarkupSafe 1.0 passlib 1.7.1 pycparser 2.18 pytz 2018.4 setuptools 39.1.0 six 1.11.0 speaklater 1.3 SQLAlchemy 1.2.7 Werkzeug 0.14.1 wheel 0.31.0 WTForms 2.1 – Kresten Apr 30 '18 at 19:42
  • Cool-- so, did setting SECURITY_EMAIL_SENDER work? If not, since we know the error is to do with the Flask-Mail part of the package, can you include your code for that? – Doobeh Apr 30 '18 at 20:01
  • SECURITY_EMAIL_SENDER didn't do any difference. I have added my e-mail config. – Kresten Apr 30 '18 at 20:13

1 Answers1

5

This is a known issue with the send_mail method in flask-security utils ref this thread .

It is corrected in this branch

One way out is to uninstall flask-security and install the updated repo

pip install git+https://github.com/mattupstate/flask-security

Of course depending on your settings you may want to do sudo pip install

Moses N. Njenga
  • 762
  • 1
  • 9
  • 19