Hi guys I'm having a problem with encoding (the bad beast :D ). I'm using django 1.1.1, sqlserver 2005 with charset latin1, sql_server.pyodbc as DATABASE_ENGINE
Here's my model-like: class MgArtbase(models.Model): cod_art = models.TextField(primary_key=True) des_articolo = models.TextField() class Meta: managed = False db_table = u'MG_ARTBASE' The record I read and immediatly save has a '\xe0' (that is a right- coded "à" in latin1) in "des_articolo" field and this causes the error you can see in the following traceback. item = MgArtbase.objects.get(cod_art = 'xxx') item.save() #error TRACEBACK Environment: Request Method: POST Request URL: http://localhost:8000/wec/ajax/articoli/tab/dati_articolo/10102010/ Django Version: 1.1.1 Python Version: 2.6.2 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'wec.web', 'compress', 'wec.std_backoffice'] Installed Middleware: ['django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.locale.LocaleMiddleware', 'wec.middleware.DBConnect.DBConnect'] Traceback: File "c:\python26\lib\site-packages\django\core\handlers\base.py" in get_response 92. response = callback(request, *callback_args, **callback_kwargs) File "c:\python26\lib\site-packages\django\contrib\auth\decorators.py" in __call__ 78. return self.view_func(request, *args, **kwargs) File "C:\Users\User\Documents\MYDOCUMENTS\RSoft\svn\wec3_HEAD\wec\.. \wec\utils\viewutils.py" in decorator 67. return func(request, *args, **kwargs) File "C:\Users\User\Documents\MYDOCUMENTS\RSoft\svn\wec3_HEAD\wec\.. \wec\utils\viewutils.py" in wrapper 40. output = func(request, *args, **kw) File "C:\Users\User\Documents\MYDOCUMENTS\RSoft\svn\wec3_HEAD\wec\.. \wec\std_backoffice\views\backoffice_ajax.py" in articoli_tab_dati_articolo 880. mgartbase.save() File "c:\python26\lib\site-packages\django\db\models\base.py" in save 410. self.save_base(force_insert=force_insert, force_update=force_update) File "c:\python26\lib\site-packages\django\db\models\base.py" in save_base 474. rows = manager.filter(pk=pk_val)._update(values) File "c:\python26\lib\site-packages\django\db\models\query.py" in _update 444. return query.execute_sql(None) File "c:\python26\lib\site-packages\django\db\models\sql \subqueries.py" in execute_sql 120. cursor = super(UpdateQuery, self).execute_sql(result_type) File "c:\python26\lib\site-packages\django\db\models\sql\query.py" in execute_sql 2369. cursor.execute(sql, params) File "c:\python26\lib\site-packages\django\db\backends\util.py" in execute 22. sql = self.db.ops.last_executed_query(self.cursor, sql, params) File "c:\python26\lib\site-packages\sql_server\pyodbc\operations.py" in last_executed_query 137. return super(DatabaseOperations, self).last_executed_query(cursor, cursor.last_sql, cursor.last_params) File "c:\python26\lib\site-packages\django\db\backends\__init__.py" in last_executed_query 213. u_params = tuple([to_unicode(val) for val in params]) File "c:\python26\lib\site-packages\django\db\backends\__init__.py" in <lambda> 211. to_unicode = lambda s: force_unicode(s, strings_only=True) File "c:\python26\lib\site-packages\django\utils\encoding.py" in force_unicode 92. raise DjangoUnicodeDecodeError(s, *e.args) Exception Type: DjangoUnicodeDecodeError at /wec/ajax/articoli/tab/ dati_articolo/10102010/ Exception Value: ('utf8', 'KARATEGI ADIDAS JUNIOR CON CINTURA IN COTONE 100% citt\xe0l', 54, 56, 'unexpected end of data') As you can see the error happens in the function "force_unicode" because it's trying to handle the string in utf-8 (by default, see the function). If I change that default "utf-8" in "latin1" things go right. That means that if the caller gave "latin1" (taken by any setting) as encoding parameter things would be ok, but so it isnt. Of course I don't want to change django-code, but how can I solve the problem? am I mistaking anything? I don't think it's a problem of data since db is latin-1 and the string is right encoded. Please help. Thank you. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.