Ticket #5538 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

global name 'body' is not defined

Reported by: anonymous Assigned to: doki_pen
Priority: normal Component: AnnouncerPlugin
Severity: critical Keywords:
Cc: Trac Release: 0.11

Description

This happens if the mime_encoding in trac.ini is set to none

2009-07-21 16:19:39,663 Trac[api] ERROR: AnnouncementSystem failed.
Traceback (most recent call last):
  File "build\bdist.win32\egg\announcerplugin\api.py", line 369, in _real_send
    distributor.distribute(transport, packages[transport], evt)
  File "build\bdist.win32\egg\announcerplugin\distributors\email_distributor.py", line 204, in distribute
    formats[format], None, to, public_cc)
  File "build\bdist.win32\egg\announcerplugin\distributors\email_distributor.py", line 287, in _do_send
    dummy = body.encode('ascii')

Attachments

Change History

10/15/09 20:18:47 changed by anonymous

I had to fix this yesterday. Got things working by commenting out that chunk of code. I'm amazed that it works for anyone else with this issue.

--- announcerplugin/distributors/email_distributor.py   (revision 6703)
+++ announcerplugin/distributors/email_distributor.py   (working copy)
@@ -282,12 +282,12 @@
                     to_unicode(provided_headers[key])
         rootMessage['Date'] = formatdate()
         # sanity check
-        if not self._charset.body_encoding:
-            try:
-                dummy = body.encode('ascii')
-            except UnicodeDecodeError:
-                raise TracError(_("Ticket contains non-ASCII chars. " \
-                                  "Please change encoding setting"))
+        #if not self._charset.body_encoding:
+        #    try:
+        #        # dummy = body.encode('ascii')
+        #    except UnicodeDecodeError:
+        #        raise TracError(_("Ticket contains non-ASCII chars. " \
+        #                          "Please change encoding setting"))
         del rootMessage['Content-Transfer-Encoding']
         rootMessage.set_charset(self._charset)
         rootMessage['Subject'] = Header(subject, self._charset)

11/24/09 16:08:35 changed by anonymous

  • owner changed from ixokai to doki_pen.

11/24/09 16:41:10 changed by doki_pen

  • status changed from new to closed.
  • resolution set to wontfix.

A better solution would have been to set your encoding as the exception suggests.

[announcer]
mime_encoding = 'base64'

Read the description of the option:

    mime_encoding = Option('announcer', 'mime_encoding', 'base64',
        """Specifies the MIME encoding scheme for emails.
        
        Valid options are 'base64' for Base64 encoding, 'qp' for
        Quoted-Printable, and 'none' for no encoding. Note that the no encoding
        means that non-ASCII characters in text are going to cause problems
        with notifications (''since 0.10'').""")

(follow-up: ↓ 5 ) 12/10/09 04:19:36 changed by anonymous

  • status changed from closed to reopened.
  • resolution deleted.

I just got hit by this.

I agree that setting the mime_encoding is an easy fix. However, even so, it is still wrong for the plugin to just die with a Python NameError?.

The plugin should either fall back to a basic format (like the original attempt to use ascii, which is still broken) or else it should log something educational like, "Set mime_enconding in your [announcer] setting in trac.ini"

Just having a random traceback is not an elegant way to handle this configuration error.

Finally, if you fall back to a default encoding, why not fall back to a default of base64?

(in reply to: ↑ 4 ) 12/10/09 04:29:27 changed by anonymous

Replying to anonymous:

Sorry, I forgot to mention in my last comment:

My trac.ini had a default mime_encoding value of none. I didn't put that there... but that is supposed to be a valid selection (as per the docs cited above) so in my opinion this is an actual bug. The plugin is supposed to handle "none" correctly.

I'm still trying to get HTML notifications to work here... but thanks for working on this, a lot of people really want pretty-looking notifications. Not everybody appreciates courier font as much as the Trac developers :)

12/18/09 20:19:30 changed by doki_pen

Yeah, body object doesn't exist. Not sure why this code sucks. I'll fix it.

12/18/09 20:27:17 changed by doki_pen

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [7280]) Update body reference to output.

Since body isn't defined. Fixes #5538

12/21/09 15:31:11 changed by doki_pen

(In [7280]) Update body reference to output.

Since body isn't defined. Fixes #5538

02/13/10 20:31:00 changed by doki_pen

(In [7589]) updates body reference to output.

Since body isn't defined. Fixes #5538 merge -r7280


Add/Change #5538 (global name 'body' is not defined)




Change Properties
Action