toconnell / kdm-manager

An interactive campaign manager for the game "Monster", by Kingdom Death. Development blog and release notes at https://blog.kdm-manager.com This project has no affiliation with Kingdom Death and is a totally independent, fan-maintained project.
http://kdm-manager.com
Other
26 stars 11 forks source link

Report Error feature: encoding error when coercing the user's message content to UTF. #484

Closed toconnell closed 6 years ago

toconnell commented 6 years ago

From the render failure email:

[5961b1908740d969d5fd6a08] was logged out of the webapp instance on ubuntu-trusty-1 due to a render failure at 2018-03-12 19:22:40.673649.

 The traceback from the exception was this:

Traceback (most recent call last):
File "/home/toconnell/kdm-manager/v1/session.py", line 61, in wrapper
 return func(self, *args, **kwargs)
File "/home/toconnell/kdm-manager/v1/session.py", line 451, in process_params
 self.report_error()
File "/home/toconnell/kdm-manager/v1/session.py", line 408, in report_error
 reply_to=self.User.user["login"],
File "/home/toconnell/kdm-manager/v1/utils.py", line 229, in send
 msg.attach(MIMEText(html_msg,'html'))
File "/usr/lib/python2.7/email/mime/text.py", line 30, in __init__
 self.set_payload(_text, _charset)
File "/usr/lib/python2.7/email/message.py", line 226, in set_payload
 self.set_charset(charset)
File "/usr/lib/python2.7/email/message.py", line 262, in set_charset
 self._payload = self._payload.encode(charset.output_charset)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2014' in position 573: ordinal not in range(128)

Looks like we want to just hit that whole user text with a hammer and drop anything we can't convert, just so the email gets sent, etc.

toconnell commented 6 years ago

Recreated in dev with an "æ" character (just to do it).

toconnell commented 6 years ago

Fixed:

@@ -226,7 +226,7 @@ class mailSession:
         if reply_to is not None:
             msg.add_header('reply-to', reply_to)

-        msg.attach(MIMEText(html_msg,'html'))
+        msg.attach(MIMEText(html_msg.encode("utf-8"),'html'))

         self.server.sendmail(self.no_reply, recipients, msg.as_string())
         self.server.quit()
@@ -297,7 +297,7 @@ def record_response_time(view_name=None, tdelta=None):
 #        logger.info("Found and removed %s old response time records!" % removed_records["n"])
         pass