Fantomas42/emencia-django-newsletter — Issue #56: Draft fix for proper output log encoding of the send_newsletter management command
Author: nnseva
Created: 2012-02-01 11:25:05+00:00
State: open

Wrong encoding leads to message from the cron like:

```
/usr/local/lib/python2.6/site-packages/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet
Starting sending newsletters...
Traceback (most recent call last):
File "/data/www/django/djangosite/manage.py", line 11, in
execute_manager(settings)
File "/usr/local/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/data/www/django/djangosite/emencia/django/newsletter/management/commands/send_newsletter.py", line 23, in handle_noargs
print 'Start emailing %s' % newsletter.title
UnicodeEncodeError: 'ascii' codec can't encode characters in position 25-31: ordinal not in range(128)
```

This fix is a draft, because proper encoding fix should probably use current system locale, fixing unprintable characters

```diff
--- send_newsletter.py.orig
+++ send_newsletter.py
@@ -20,7 +20,7 @@
mailer = Mailer(newsletter)
if mailer.can_send:
if verbose:
- print 'Start emailing %s' % newsletter.title
+ print 'Start emailing %s' % unicode(newsletter.title).encode('utf-8')
mailer.run()

if verbose: