werkzeug.local.LocalProxy object passed to sanitize_address method
Hi, sanitize_address is receiving a LocalProxy object instead of an str or basestring. I am using Python 2.7.
File "/home/abc/sites/hempafy1/env/local/lib/python2.7/site-packages/flask_security/registerable.py", line 41, in register_user
'welcome', user=user, confirmation_link=confirmation_link)
File "/home/abc/sites/hempafy1/env/local/lib/python2.7/site-packages/flask_security/utils.py", line 401, in send_mail
mail.send(msg)
File "/home/abc/sites/hempafy1/env/local/lib/python2.7/site-packages/flask_mail.py", line 496, in send
message.send(connection)
File "/home/abc/sites/hempafy1/env/local/lib/python2.7/site-packages/flask_mail.py", line 431, in send
connection.send(self)
File "/home/abc/sites/hempafy1/env/local/lib/python2.7/site-packages/flask_mail.py", line 192, in send
self.host.sendmail(sanitize_address(envelope_from or message.sender),
File "/home/abc/sites/hempafy1/env/local/lib/python2.7/site-packages/flask_mail.py", line 109, in sanitize_address
nm, addr = addr
ValueError: too many values to unpack
I put the following in the flask_mail.py
def sanitize_address(addr, encoding='utf-8'):
if isinstance(addr, string_types):
addr = parseaddr(force_text(addr))
elif isinstance(addr, LocalProxy):
addr = parseaddr(force_text(addr))
nm, addr = addr
Checking to see if object is LocalProxy. Is this a good way to solve the issue? or is it something that must be changed in flask_security?
Thanks.
Yes, I'm about to use your fix, but I'd like to see this either formally accepted or something. What's going on with this?
You're probably passing Flask-Login's current_user as the sender. This doesn't make sense, not does converting it to a string, which wouldn't be a valid email anyway. Pass user.email (or whatever the email is) as the sender.
This code should not be merged, you should fix the data you're passing.