Hi All, I have a Book table in MySQL db. I configured my MySQL db and table to use utf8 character set and the utf8_general_ci collation I created a simple Book class and tried to save unicode data using (a)the django shell (b) the data entry screen created by using ModelAdmin class
In both cases I was getting errors. The column in the model class is defined as having Charfield. I checked this link https://docs.djangoproject.com/en/1.5/ref/unicode/. I tried to use smart_text function. But it did not work. I am using python 2.7, django1.5, mysql 5x in windows box The text I am trying to save is a devanagari script word (wikipedia lang code "hi"). Below are the error messages. can some one please help. regards ---------------text --------------------------- s="श्रीमद्भगवद्गीता" print (s) शà¥�रीमदà¥�à¤à¤—वदà¥�गीता ------------Smart Text Error -------------------------------- from django.utils.encoding import * title=smart_text("श्रीमद्भगवद्गीता", encoding='utf-8', strings_only=False, errors='strict') print(title) Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Softwares\Python2.7.3\lib\encodings\cp1252.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_table) UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-15: character maps to <undefined> -----------------Error trying to save the model from shell------------------------------ gita4 = Book(bookName= "श्रीमद्भगवद्गीता") gita4.save() Error message: Warning: Incorrect string value: '\xE0\xA4\xB6\xE0\xA5\x8D...' for column 'bookName' at row 1 ------------------------- Full StackTrace ---------------------------------------------------- Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Softwares\Python2.7.3\lib\site-packages\django\db\models\base.py", line 546, in save force_update=force_update, update_fields=update_fields) File "C:\Softwares\Python2.7.3\lib\site-packages\django\db\models\base.py", line 650, in save_base result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw) File "C:\Softwares\Python2.7.3\lib\site-packages\django\db\models\manager.py", line 215, in _insert return insert_query(self.model, objs, fields, **kwargs) File "C:\Softwares\Python2.7.3\lib\site-packages\django\db\models\query.py", line 1661, in insert_query return query.get_compiler(using=using).execute_sql(return_id) File "C:\Softwares\Python2.7.3\lib\site-packages\django\db\models\sql\compiler.py", line 937, in execute_sql cursor.execute(sql, params) File "C:\Softwares\Python2.7.3\lib\site-packages\django\db\backends\util.py", line 41, in execute return self.cursor.execute(sql, params) File "C:\Softwares\Python2.7.3\lib\site-packages\django\db\backends\mysql\base.py", line 120, in execute return self.cursor.execute(query, args) File "C:\Softwares\Python2.7.3\lib\site-packages\MySQLdb\cursors.py", line 204, in execute if not self._defer_warnings: self._warning_check() File "C:\Softwares\Python2.7.3\lib\site-packages\MySQLdb\cursors.py", line 117, in _warning_check warn(w[-1], self.Warning, 3) Warning: Incorrect string value: '\xE0\xA4\xB6\xE0\xA5\x8D...' for column 'bookName' at row 1 -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.