OperationalError 1366 Incorrect string value ... for column 'message'

2024 views
Skip to first unread message

SeanB

unread,
Feb 20, 2009, 8:00:43 PM2/20/09
to Django users
I have an application that include Unicode strings (Greek and Hebrew),
running on a dev machine and an (inside the firewall) release machine
configured (to the best of my ability) with the same Python, Django,
MySql and connector.

When editing an object containing one of these strings on the release
machine, in the admin interface, when i save i get:
OperationalError at /admin/realia/lemmarelation/1597/

(1366, "Incorrect string value: '\\xE1\\xBC\\x80\\xCE\\xAE\\xCF...'
for column 'message' at row 1")

Request Method: POST
Request URL: http://debuild/admin/realia/lemmarelation/1597/
Exception Type: OperationalError
Exception Value:

(1366, "Incorrect string value: '\\xE1\\xBC\\x80\\xCE\\xAE\\xCF...'
for column 'message' at row 1")

Exception Location: C:\Python24\Lib\site-packages\MySQLdb
\connections.py in defaulterrorhandler, line 35
Python Executable: C:\Program Files\Apache Software Foundation
\Apache2.2\bin\httpd.exe
Python Version: 2.4.3
Python Path: ['c:/design.ed/django/logos/', 'C:\\Python24\\lib\\site-
packages\\setuptools-0.6c6-py2.4.egg', 'C:\\Python24\\Lib\\site-
packages\\django', 'C:\\design.ed\\django', 'C:\\Program Files\\Apache
Software Foundation\\Apache2.2', 'C:\\WINDOWS\\system32\
\python24.zip', 'c:\\python24\\lib\\site-packages', 'C:\\Python24\
\Lib', 'C:\\Python24\\DLLs', 'C:\\Python24\\Lib\\lib-tk', 'C:\\Program
Files\\Apache Software Foundation\\Apache2.2\\bin', 'C:\\Python24', 'c:
\\design.ed\\python\\libronix', 'C:\\Python24\\lib\\site-packages\
\win32', 'C:\\Python24\\lib\\site-packages\\win32\\lib', 'C:\\Python24\
\lib\\site-packages\\Pythonwin']
Server time: Fri, 20 Feb 2009 16:51:59 -0800

'message' isn't in my model, so it's breaking somewhere in the Django
part, but i'm not sure why, or how to fix it. And i can't find
anything different about my two environments that explains why it
breaks on one machine, but works fine on the other. What seems like
the likely culprit is a UTF-8 string, whose collating method is
utf8_general_ci. It's not a single data value: attempting to edit any
object in this table seems to raise this error.

Here's the traceback:
Environment:

Request Method: POST
Request URL: http://debuild/admin/realia/lemmarelation/1597/
Django Version: 1.0.2 final
Python Version: 2.4.3
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'logos.lcv',
'logos.places',
'logos.names',
'logos.agents',
'logos.realia']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware')


Traceback:
File "C:\Python24\Lib\site-packages\django\core\handlers\base.py" in
get_response
86. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Python24\Lib\site-packages\django\contrib\admin\sites.py" in
root
157. return self.model_page(request, *url.split('/',
2))
File "C:\Python24\Lib\site-packages\django\views\decorators\cache.py"
in _wrapped_view_func
44. response = view_func(request, *args, **kwargs)
File "C:\Python24\Lib\site-packages\django\contrib\admin\sites.py" in
model_page
176. return admin_obj(request, rest_of_url)
File "C:\Python24\Lib\site-packages\django\contrib\admin\options.py"
in __call__
197. return self.change_view(request, unquote(url))
File "C:\Python24\Lib\site-packages\django\db\transaction.py" in
_commit_on_success
238. res = func(*args, **kw)
File "C:\Python24\Lib\site-packages\django\contrib\admin\options.py"
in change_view
587. return self.response_change(request,
new_object)
File "C:\Python24\Lib\site-packages\django\contrib\admin\options.py"
in response_change
454. self.message_user(request, msg + ' ' + _("You may
edit it again below."))
File "C:\Python24\Lib\site-packages\django\contrib\admin\options.py"
in message_user
363. request.user.message_set.create(message=message)
File "C:\Python24\Lib\site-packages\django\db\models\fields
\related.py" in create
310. return super(RelatedManager, self).create
(**kwargs)
File "C:\Python24\Lib\site-packages\django\db\models\manager.py" in
create
99. return self.get_query_set().create(**kwargs)
File "C:\Python24\Lib\site-packages\django\db\models\query.py" in
create
319. obj.save(force_insert=True)
File "C:\Python24\Lib\site-packages\django\db\models\base.py" in save
311. self.save_base(force_insert=force_insert,
force_update=force_update)
File "C:\Python24\Lib\site-packages\django\db\models\base.py" in
save_base
383. result = manager._insert(values,
return_id=update_pk)
File "C:\Python24\Lib\site-packages\django\db\models\manager.py" in
_insert
138. return insert_query(self.model, values, **kwargs)
File "C:\Python24\Lib\site-packages\django\db\models\query.py" in
insert_query
894. return query.execute_sql(return_id)
File "C:\Python24\Lib\site-packages\django\db\models\sql
\subqueries.py" in execute_sql
309. cursor = super(InsertQuery, self).execute_sql(None)
File "C:\Python24\Lib\site-packages\django\db\models\sql\query.py" in
execute_sql
1734. cursor.execute(sql, params)
File "C:\Python24\Lib\site-packages\django\db\backends\util.py" in
execute
19. return self.cursor.execute(sql, params)
File "C:\Python24\Lib\site-packages\django\db\backends\mysql\base.py"
in execute
83. return self.cursor.execute(query, args)
File "C:\Python24\Lib\site-packages\MySQLdb\cursors.py" in execute
166. self.errorhandler(self, exc, value)
File "C:\Python24\Lib\site-packages\MySQLdb\connections.py" in
defaulterrorhandler
35. raise errorclass, errorvalue

Exception Type: OperationalError at /admin/realia/lemmarelation/1597/
Exception Value: (1366, "Incorrect string value: '\\xE1\\xBC\\x80\\xCE\
\xAE\\xCF...' for column 'message' at row 1")

Karen Tracey

unread,
Feb 20, 2009, 8:18:52 PM2/20/09
to django...@googlegroups.com
On Fri, Feb 20, 2009 at 8:00 PM, SeanB <Sean....@gmail.com> wrote:

I have an application that include Unicode strings (Greek and Hebrew),
running on a dev machine and an (inside the firewall) release machine
configured (to the best of my ability) with the same Python, Django,
MySql and connector.

When editing an object containing one of these strings on the release
machine, in the admin interface, when i save i get:
OperationalError at /admin/realia/lemmarelation/1597/

(1366, "Incorrect string value: '\\xE1\\xBC\\x80\\xCE\\xAE\\xCF...'
for column 'message' at row 1")

Request Method:         POST
Request URL:    http://debuild/admin/realia/lemmarelation/1597/
Exception Type:         OperationalError
Exception Value:

(1366, "Incorrect string value: '\\xE1\\xBC\\x80\\xCE\\xAE\\xCF...'
for column 'message' at row 1")

[snip]


'message' isn't in my model, so it's breaking somewhere in the Django
part, but i'm not sure why, or how to fix it. And i can't find
anything different about my two environments that explains why it
breaks on one machine, but works fine on the other. What seems like
the likely culprit is a UTF-8 string, whose collating method is
utf8_general_ci. It's not a single data value: attempting to edit any
object in this table seems to raise this error.

Check the auth_message table definition (output of create table in mysql) on the machine that works vs. the one that fails.  It sounds like on the failing machine this table may have a default latin1 charset instead of utf8, so whenever the Django admin code attempts to insert a message (e.g. "XYZ was changed, you may edit it again below") that refers to an object where "XYZ" is going to contain chars not representable in latin1, you get an error.

Karen

SeanB

unread,
Feb 23, 2009, 12:37:35 PM2/23/09
to Django users
Bingo, that was precisely the problem: altering the message field to
use utf8_general_ci solved it. Thanks, i was really pulling my hair
out over this one!

Sean

On Feb 20, 5:18 pm, Karen Tracey <kmtra...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages