Django utf-8和django-mailer陌生

时间:2010-08-24 18:41:01

标签: python django encoding utf-8 mailer

来自主干http://github.com/jtauber/django-mailer/tree/master/docs/

的最新django邮件程序

使用Postgresql 8.4,sqlite3

进行测试

模板

{{ 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)

错误

环境:

请求方法:POST 请求网址:http://localhost:8000/deals/share/ Django版本:1.2 SVN-13596 Python版本:2.6.5 已安装的应用程序 [ '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',  “邮件”,  “配置文件”,  “标签”,  “大规模杀伤性武器”,  '核心',  '交易'] 已安装的中间件: ( '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
  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

这看起来很奇怪,

有关它可能来自哪里的任何提示?

1 个答案:

答案 0 :(得分:0)

U + 00E9是带有急性的拉丁文小写字母E.

这可能是问题的来源(不一定是原因):'title':u"éééààà",

原因可能类似于your_title.encode('latin1').decode('utf8')(当然不是一步到位)。