import sys, codecs, locale
sys.stdout = codecs.getwriter(locale.getpreferredencoding())
(sys.stdout)

or you can hard-code locale.getpreferredencoding() as 'utf-8'

On Jun 7, 2:19 am, "Carlos A. Carnero Delgado"
<carloscarn...@gmail.com> wrote:
> Hi there!
>
> I'm having a problem with a custom management command. Running
> interactively on the console will work perfectly, merrily printing its
> output in Unicode (I need that; accented characters among other
> things).
>
> But, if I put that command in a cron job, it will fail with
>
>   UnicodeEncodeError: 'ascii' codec can't encode character
>
> (getting those from cron's email messages). I *think* it's because the
> interactive environment is different from cron's. I've tried putting a
> LANG=en_US.UTF-8 into cron's (dunno if that's Ubuntu specific) but I'm
> getting the same error.
>
> Any ideas?
>
> Best regards,
> Carlos.
>
>   >>> import sys
>   >>> print sys.platform
>   linux2
>   >>> print sys.version
>   2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
>   [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)]'
>   >>> import django
>   >>> django.VERSION
>   (1, 1, 0, 'beta', 1)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to