Convert subject and body to unicode before sending mail
Not doing this was raising an exception :
Traceback (most recent call last):
File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/gluon/restricted.py, line 227, in restricted
exec ccode in environment
File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/applications/foundit/controllers/default.py, line 127, in <module>
File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/gluon/globals.py, line 393, in <lambda>
self._caller = lambda f: f()
File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/applications/foundit/controllers/default.py, line 34, in user
return dict(form=auth())
File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/gluon/tools.py, line 1595, in __call__
return getattr(self, args[0])()
File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/gluon/tools.py, line 3272, in request_reset_password
if self.email_reset_password(user):
File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/gluon/tools.py, line 3296, in email_reset_password
message=self.messages.reset_password % d):
File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/gluon/tools.py, line 798, in send
subject=subject, body=text, **xcc)
File /base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py, line 402, in send_mail
message.send(make_sync_call=make_sync_call)
File /base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py, line 1108, in send
message = self.ToProto()
File /base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py, line 1350, in ToProto
message = super(EmailMessage, self).ToProto()
File /base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py, line 1046, in ToProto
message.set_subject(_to_str(self.subject))
File cpp_message.pyx, line 124, in cpp_message.SetScalarAccessors.Setter (third_party/apphosting/python/protobuf/proto1/cpp_message.cc:2229)
TypeError: <class 'gluon.languages.lazyT'> has type <class 'gluon.languages.lazyT'>, but expected one of: str, unicode
This commit is contained in:
1 parent
587ff56a94
commit
a6226d6391
1 file changed
+5
-5
+5
-5
@@ -767,8 +767,8 @@ class Mail(object):
|
|||||||
if self.settings.server == 'logging':
|
if self.settings.server == 'logging':
|
||||||
logger.warn('email not sent\n%s\nFrom: %s\nTo: %s\nSubject: %s\n\n%s\n%s\n' %
|
logger.warn('email not sent\n%s\nFrom: %s\nTo: %s\nSubject: %s\n\n%s\n%s\n' %
|
||||||
('-' * 40, sender,
|
('-' * 40, sender,
|
||||||
', '.join(to), subject,
|
', '.join(to), subject,
|
||||||
text or html, '-' * 40))
|
text or html, '-' * 40))
|
||||||
elif self.settings.server == 'gae':
|
elif self.settings.server == 'gae':
|
||||||
xcc = dict()
|
xcc = dict()
|
||||||
if cc:
|
if cc:
|
||||||
@@ -786,16 +786,16 @@ class Mail(object):
|
|||||||
if attachments:
|
if attachments:
|
||||||
result = mail.send_mail(
|
result = mail.send_mail(
|
||||||
sender=sender, to=origTo,
|
sender=sender, to=origTo,
|
||||||
subject=subject, body=text, html=html,
|
subject=unicode(subject), body=unicode(text), html=html,
|
||||||
attachments=attachments, **xcc)
|
attachments=attachments, **xcc)
|
||||||
elif html and (not raw):
|
elif html and (not raw):
|
||||||
result = mail.send_mail(
|
result = mail.send_mail(
|
||||||
sender=sender, to=origTo,
|
sender=sender, to=origTo,
|
||||||
subject=subject, body=text, html=html, **xcc)
|
subject=unicode(subject), body=unicode(text), html=html, **xcc)
|
||||||
else:
|
else:
|
||||||
result = mail.send_mail(
|
result = mail.send_mail(
|
||||||
sender=sender, to=origTo,
|
sender=sender, to=origTo,
|
||||||
subject=subject, body=text, **xcc)
|
subject=unicode(subject), body=unicode(text), **xcc)
|
||||||
else:
|
else:
|
||||||
smtp_args = self.settings.server.split(':')
|
smtp_args = self.settings.server.split(':')
|
||||||
kwargs = dict(timeout=self.settings.timeout)
|
kwargs = dict(timeout=self.settings.timeout)
|
||||||
|
|||||||
Reference in new issue
Block a user