TurboMail and unicode problem

33 views
Skip to first unread message

Johnny Blonde

unread,
May 2, 2007, 7:51:11 AM5/2/07
to TurboGears
Hello Group,

i am trying to set up some scheduled tasks which will have to send
emails.

the email-content is to be rendered by kid and then passed to an
instance of TurboMail.Message

the template is rendered correctly, but when passing it to the
message, i receive encoding errors.
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
67: ordinal not in range(128).

what can i do about that? i think i´m using the latest version of
turbomail 2.0.3

Regards,
Frank

dmhwsm

unread,
May 2, 2007, 9:16:46 AM5/2/07
to TurboGears

> the template is rendered correctly, but when passing it to the
> message, i receive encoding errors.
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 67: ordinal not in range(128).

once I have had the same error-message (working with an utf-8 encoded
database)

it was solved by creating the file
/usr/lib64/python2.4/site-packages/sitecustomize.py
containing the two following lines :
import sys
sys.setdefaultencoding("utf-8")

but this can disturb your non utf-8 python-scripts

happy pythoning

Herbert

Johnny Blonde

unread,
May 2, 2007, 9:55:07 AM5/2/07
to TurboGears
thanks - that solved it... i hope all other scripts that are run on
this server are utf-8 too...

Diez B. Roggisch

unread,
May 4, 2007, 4:55:00 AM5/4/07
to turbo...@googlegroups.com, dmhwsm

Because of this it's a really bad advice. Don't do that!

Diez

Diez B. Roggisch

unread,
May 4, 2007, 4:56:02 AM5/4/07
to turbo...@googlegroups.com, Johnny Blonde

Showing us the code would help. I'm sending utf-8-encoded emails just fine
using TurboMail & don't have to tweak the systems default encoding.

Diez

Johnny Blonde

unread,
May 4, 2007, 6:45:44 AM5/4/07
to TurboGears
this is actually the code:
http://paste.turbogears.org/paste/1256

nothing special i think...?

On 4 Mai, 10:56, "Diez B. Roggisch" <diez.roggi...@artnology.com>
wrote:

Diez B. Roggisch

unread,
May 4, 2007, 8:07:43 AM5/4/07
to turbo...@googlegroups.com, Johnny Blonde
On Friday 04 May 2007 12:45, Johnny Blonde wrote:
> this is actually the code:
> http://paste.turbogears.org/paste/1256
>
> nothing special i think...?

Well, apart from you not passing the subject and the rendered not as
unicode-objects, but as byte-strings of course.

Which will result in the byte-string being encoded to a unicode object with
the standard encoding - ascii.

And of course that fails.

I do it like this:

message.rich = unicode(kid_engine.render(params,
template='varms.templates.sales.groupvisits_email'), 'utf-8')

Diez

Johnny Blonde

unread,
May 7, 2007, 5:21:28 AM5/7/07
to TurboGears
thanks a lot diez,

that works perfectly.

Frank

On 4 Mai, 14:07, "Diez B. Roggisch" <diez.roggi...@artnology.com>
wrote:

Reply all
Reply to author
Forward
0 new messages