Django utf-8 and django-mailer strangeness
Latest django mailer from trunk http://github.com/jtauber/django-mailer/tree/master/docs/
Tested with Postgresql 8.4, sqlite3
template
{{ title }}
forms.py
#-*- coding: utf-8 -*-
if "mailer" in settings.INSTALLED_APPS:
from mailer import send_mail
else:
from django.core.mail import send_mail
...
body_txt = render_to_string(
'mails/share_deal/email_body.txt',
{
'title':u"éééààà",
}
)
send_mail( "", body_txt , "foo@ff.ff", ["bar@kl.fd"], fail_silently=True)
Error
Environment:
Request Method: POST Request URL: http://localhost:8000/deals/share/ Django Version: 1.2 SVN-13596 Python Version: 2.6.5 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.admin', 'django_extensions', 'django.contrib.markup', 'django.contrib.comments', 'ajaxcomments', 'mailer', 'profiles', 'tagging', 'wmd', 'core', 'deals'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/home/gregory/.virtualenvs/alpha/src/django/django/core/handlers/base.py" in get_response
100. response = callback(request, *callback_args, **callback_kwargs)
File "/home/gregory/projects/casadeal/casadeal/core/decorators.py" in wrap
12. return f(request, *args, **kwargs)
File "/home/gregory/.virtualenvs/alpha/src/django/django/views/decorators/http.py" in inner
37. return func(request, *args, **kwargs)
File "/home/gregory/projects/casadeal/casadeal/deals/views.py" in share_deal
22. form.send_mail()
File "/home/gregory/projects/casadeal/casadeal/deals/forms.py" in send_mail
89. fail_silently=True)
File "/home/gregory/.virtualenvs/casadeal/src/django-mailer/mailer/__init__.py" in send_mail
45. priority=priority).save()
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/models/base.py" in save
435. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/models/base.py" in save_base
开发者_如何学Python 528. result = manager._insert(values, return_id=update_pk, using=using)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/models/manager.py" in _insert
195. return insert_query(self.model, values, **kwargs)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/models/query.py" in insert_query
1479. return query.get_compiler(using=using).execute_sql(return_id)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/models/sql/compiler.py" in execute_sql
783. cursor = super(SQLInsertCompiler, self).execute_sql(None)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/models/sql/compiler.py" in execute_sql
727. cursor.execute(sql, params)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/backends/util.py" in execute
15. return self.cursor.execute(sql, params)
File "/home/gregory/.virtualenvs/alpha/src/django/django/db/backends/postgresql_psycopg2/base.py" in execute
44. return self.cursor.execute(query, args)
Exception Type: DatabaseError at /deals/share/
Exception Value: ERREUR: séquence d'octets invalide pour l'encodage « UTF8 » : 0xe9e9e9
HINT: Cette erreur peut aussi survenir si la séquence d'octets ne correspond pas
au jeu de caractères attendu par le serveur, le jeu étant contrôlé par
« client_encoding ».
Basically it says that the encoding was not valid for UTF8 and contained 0xe9e9e9
This seems quite strange,
Any hints on where it could come from ?
U+00E9 is LATIN SMALL LETTER E WITH ACUTE.
This MAY be the source (not necessarily the cause) of the problem: 'title':u"éééààà",
.
Cause may be something like your_title.encode('latin1').decode('utf8')
(not in one step, of course).
精彩评论