Modify

Opened 11 years ago

Closed 11 years ago

#11354 closed defect (duplicate)

UnicodeEncodeError on wiki and ticket notifications containing non-ascii codes

Reported by: anonymous Owned by: Steffen Hoffmann
Priority: normal Component: AnnouncerPlugin
Severity: normal Keywords:
Cc: nebojsa@… Trac Release: 1.0

Description

If I choose diff for wiki pages, and if there is a non ascii in the diff itself, exception is thrown, visible only in trac log:

    self._do_send(transport, event, k, v, fmtdict[k])
  File "build/bdist.linux-armv5tel/egg/announcer/distributors/mail.py", line 481, in _do_send
    msgText = MIMEText(alternate_output, alt_msg_format)
  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'\u0161' in position 259: ordinal not in range(128)

I have traced problem down to announcer/distributors/mail.py. Following patch fixes problem for me:

Index: announcer/distributors/mail.py
===================================================================
--- announcer/distributors/mail.py      (revision 13419)
+++ announcer/distributors/mail.py      (working copy)
@@ -478,16 +478,16 @@
             rootMessage.attach(parentMessage)
 
             alt_msg_format = 'html' in alternate_style and 'html' or 'plain'
-            msgText = MIMEText(alternate_output, alt_msg_format)
-            msgText.set_charset(self._charset)
+            msgText = MIMEText(alternate_output, alt_msg_format, "utf-8")
+            # msgText.set_charset(self._charset)
             parentMessage.attach(msgText)
         else:
             parentMessage = rootMessage
 
         msg_format = 'html' in format and 'html' or 'plain'
-        msgText = MIMEText(output, msg_format)
-        del msgText['Content-Transfer-Encoding']
-        msgText.set_charset(self._charset)
+        msgText = MIMEText(output, msg_format, "utf-8")
+        # del msgText['Content-Transfer-Encoding']
+        # msgText.set_charset(self._charset)
         # According to RFC 2046, the last part of a multipart message is best
         #   and preferred.
         parentMessage.attach(msgText)

I am running python 2.7.5

Attachments (0)

Change History (2)

comment:1 Changed 11 years ago by nebojsa@…

Cc: nebojsa@… added; anonymous removed

comment:2 Changed 11 years ago by Jun Omae

Resolution: duplicate
Status: newclosed

A duplicate of #10974.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Steffen Hoffmann.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.