Opened 16 years ago

Closed 16 years ago

Last modified 12 years ago

#8585 closed (worksforme)

InterfaceError with MySQLdb set_character_set

Reported by: khsing Owned by: nobody
Component: contrib.admin Version: 1.0-beta
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have syncdb and runserver via console mode without any error. but when I want to run it via mod_python, and I got some error like this.

Environment:

Request Method: GET
Request URL: http://218.30.114.220/infocoll/admin/
Django Version: 1.0-beta_1-SVN-unknown
Python Version: 2.4.3
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.admin',
 'infocoll.info',
 'infocoll.log']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Traceback:
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/sites.py" in root
  155.         if not self.has_permission(request):
File "/usr/lib/python2.4/site-packages/django/contrib/admin/sites.py" in has_permission
  113.         return request.user.is_authenticated() and request.user.is_staff
File "/usr/lib/python2.4/site-packages/django/contrib/auth/middleware.py" in __get__
  5.             request._cached_user = get_user(request)
File "/usr/lib/python2.4/site-packages/django/contrib/auth/__init__.py" in get_user
  78.         user_id = request.session[SESSION_KEY]
File "/usr/lib/python2.4/site-packages/django/contrib/sessions/backends/base.py" in __getitem__
  46.         return self._session[key]
File "/usr/lib/python2.4/site-packages/django/contrib/sessions/backends/base.py" in _get_session
  168.                 self._session_cache = self.load()
File "/usr/lib/python2.4/site-packages/django/contrib/sessions/backends/db.py" in load
  15.                 expire_date__gt=datetime.datetime.now()
File "/usr/lib/python2.4/site-packages/django/db/models/manager.py" in get
  81.         return self.get_query_set().get(*args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in get
  295.         num = len(clone)
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in __len__
  151.                 self._result_cache = list(self.iterator())
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in iterator
  266.         for row in self.query.results_iter():
File "/usr/lib/python2.4/site-packages/django/db/models/sql/query.py" in results_iter
  200.         for rows in self.execute_sql(MULTI):
File "/usr/lib/python2.4/site-packages/django/db/models/sql/query.py" in execute_sql
  1613.         cursor = self.connection.cursor()
File "/usr/lib/python2.4/site-packages/django/db/backends/__init__.py" in cursor
  56.         cursor = self._cursor(settings)
File "/usr/lib/python2.4/site-packages/django/db/backends/mysql/base.py" in _cursor
  221.             self.connection = Database.connect(**kwargs)
File "build/bdist.linux-x86_64/egg/MySQLdb/__init__.py" in Connect
  74.     return Connection(*args, **kwargs)
File "build/bdist.linux-x86_64/egg/MySQLdb/connections.py" in __init__
  198.         self.set_character_set(charset)
File "build/bdist.linux-x86_64/egg/MySQLdb/connections.py" in set_character_set
  277.                 super(Connection, self).set_character_set(charset)

Exception Type: InterfaceError at /infocoll/admin/
Exception Value: (0, '')

here is some info of mine

  • mysql
    Server version:		5.1.26-rc-log Source distribution
    Protocol version:	10
    Connection:		Localhost via UNIX socket
    Server characterset:	utf8
    Db     characterset:	utf8
    Client characterset:	utf8
    Conn.  characterset:	utf8
    
  • host
    Linux JA_PUBLIC_TEST_114_220 2.6.18-53.el5 #1 SMP Mon Nov 12 02:14:55 EST 2007 x86_64 x86_64 x86_64 GNU/Linux
    Python 2.4.3
    MySQL-python-1.2.2
    

Change History (9)

comment:1 by khsing, 16 years ago

there are mysql client info, the client version is (3,23), but I compile MySQLdb with MySQL 5.0.54

{{{CLIENT
<module 'MySQLdb.constants.CLIENT' from '/usr/lib64/python2.4/site-packages/MySQLdb/constants/CLIENT.py'>
FIELD_TYPE
<module 'MySQLdb.constants.FIELD_TYPE' from '/usr/lib64/python2.4/site-packages/MySQLdb/constants/FIELD_TYPE.py'>
WeakValueDictionary
<class weakref.WeakValueDictionary at 0x2aaab4b840b0>
_get_string_decoder
<function _get_string_decoder at 0xad590c8>
_get_string_literal
<function _get_string_literal at 0xae49cf8>
_get_unicode_literal
<function _get_unicode_literal at 0xad59050>
args
()
charset
'utf8'
client_flag
0
client_version
(3, 23)
}}}

  • /usr/include/mysql/mysql_version.h
    #define PROTOCOL_VERSION        10
    #define MYSQL_SERVER_VERSION        "5.0.45"
    #define MYSQL_BASE_VERSION      "mysqld-5.0"
    
  • MySQLdb
    >>> MySQLdb._mysql.get_client_info()
    '5.0.45'
    

comment:2 by Karen Tracey, 16 years ago

I doubt this is a bug in Django. Given the error and the fact that it works from the development server console I'd guess for some reason when running under Apache the wrong shared library is being loaded or something. From a console you could try:

python -v
import MySQLdb 

That will print out where MySQLdb is being loaded from in the case where it works. If that looks different than the build/bdist.linux-x86_64/egg/MySQLdb location being used by Apache that would be a clue.

(Actually from your previous note -- though the formatting didn't work -- the MySQLdb you built should be under /usr/lib64/python2.4/site-packages/MySQLdb? That doesn't look to be where it is getting pulled from when Apache/mod_ptyhon runs, which could be the problem.)

comment:3 by khsing, 16 years ago

there result of "import MySQLdb" via "python -v "

>>>import MySQLdb
import MySQLdb # directory /usr/lib64/python2.4/site-packages/MySQLdb
# /usr/lib64/python2.4/site-packages/MySQLdb/__init__.pyc matches /usr/lib64/python2.4/site-packages/MySQLdb/__init__.py
import MySQLdb # precompiled from /usr/lib64/python2.4/site-packages/MySQLdb/__init__.pyc
# /usr/lib64/python2.4/site-packages/MySQLdb/release.pyc matches /usr/lib64/python2.4/site-packages/MySQLdb/release.py
import MySQLdb.release # precompiled from /usr/lib64/python2.4/site-packages/MySQLdb/release.pyc
dlopen("/usr/lib64/python2.4/site-packages/_mysql.so", 2);
# /usr/lib64/python2.4/site-packages/_mysql_exceptions.pyc matches /usr/lib64/python2.4/site-packages/_mysql_exceptions.py
import _mysql_exceptions # precompiled from /usr/lib64/python2.4/site-packages/_mysql_exceptions.pyc
import _mysql # dynamically loaded from /usr/lib64/python2.4/site-packages/_mysql.so
import MySQLdb.constants # directory /usr/lib64/python2.4/site-packages/MySQLdb/constants
# /usr/lib64/python2.4/site-packages/MySQLdb/constants/__init__.pyc matches /usr/lib64/python2.4/site-packages/MySQLdb/constants/__init__.py
import MySQLdb.constants # precompiled from /usr/lib64/python2.4/site-packages/MySQLdb/constants/__init__.pyc
# /usr/lib64/python2.4/site-packages/MySQLdb/constants/FIELD_TYPE.pyc matches /usr/lib64/python2.4/site-packages/MySQLdb/constants/FIELD_TYPE.py
import MySQLdb.constants.FIELD_TYPE # precompiled from /usr/lib64/python2.4/site-packages/MySQLdb/constants/FIELD_TYPE.pyc
# /usr/lib64/python2.4/site-packages/MySQLdb/times.pyc matches /usr/lib64/python2.4/site-packages/MySQLdb/times.py
import MySQLdb.times # precompiled from /usr/lib64/python2.4/site-packages/MySQLdb/times.pyc
dlopen("/usr/lib64/python2.4/lib-dynload/timemodule.so", 2);
import time # dynamically loaded from /usr/lib64/python2.4/lib-dynload/timemodule.so
dlopen("/usr/lib64/python2.4/lib-dynload/datetime.so", 2);
import datetime # dynamically loaded from /usr/lib64/python2.4/lib-dynload/datetime.so
# /usr/lib64/python2.4/sets.pyc matches /usr/lib64/python2.4/sets.py
import sets # precompiled from /usr/lib64/python2.4/sets.pyc
# /usr/lib64/python2.4/__future__.pyc matches /usr/lib64/python2.4/__future__.py
import __future__ # precompiled from /usr/lib64/python2.4/__future__.pyc
dlopen("/usr/lib64/python2.4/lib-dynload/itertoolsmodule.so", 2);
import itertools # dynamically loaded from /usr/lib64/python2.4/lib-dynload/itertoolsmodule.so

comment:4 by Malcolm Tredinnick, 16 years ago

If you look in the original traceback you posted, you can see that the code there is accessing MySQLdb from build/bdist.linux-x86_64/egg/MySQLdb/. So the code there is running a different version. You should investigate that.

I really don't see that this is a Django bug, though. It looks like the character setting attempt is failing inside MySQLdb, which suggests mismatched (or a very old) version.

comment:5 by khsing, 16 years ago

yes, the first traceback I have posted was using a binary MySQLdb module(/usr/lib64/python2.4/site-packages/MySQL_python-1.2.2-py2.4-linux-x86_64.egg).
and now, I have change to using /usr/lib64/python2.4/site-packages/MySQLdb, but the error still exist. here is new traceback info below.

Environment:

Request Method: GET
Request URL: http://218.30.114.220/infocoll/admin/
Django Version: 1.0-beta_1-SVN-unknown
Python Version: 2.4.3
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.admin',
 'infocoll.info',
 'infocoll.log']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Traceback:
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/sites.py" in root
  155.         if not self.has_permission(request):
File "/usr/lib/python2.4/site-packages/django/contrib/admin/sites.py" in has_permission
  113.         return request.user.is_authenticated() and request.user.is_staff
File "/usr/lib/python2.4/site-packages/django/contrib/auth/middleware.py" in __get__
  5.             request._cached_user = get_user(request)
File "/usr/lib/python2.4/site-packages/django/contrib/auth/__init__.py" in get_user
  78.         user_id = request.session[SESSION_KEY]
File "/usr/lib/python2.4/site-packages/django/contrib/sessions/backends/base.py" in __getitem__
  46.         return self._session[key]
File "/usr/lib/python2.4/site-packages/django/contrib/sessions/backends/base.py" in _get_session
  168.                 self._session_cache = self.load()
File "/usr/lib/python2.4/site-packages/django/contrib/sessions/backends/db.py" in load
  15.                 expire_date__gt=datetime.datetime.now()
File "/usr/lib/python2.4/site-packages/django/db/models/manager.py" in get
  81.         return self.get_query_set().get(*args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in get
  295.         num = len(clone)
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in __len__
  151.                 self._result_cache = list(self.iterator())
File "/usr/lib/python2.4/site-packages/django/db/models/query.py" in iterator
  266.         for row in self.query.results_iter():
File "/usr/lib/python2.4/site-packages/django/db/models/sql/query.py" in results_iter
  200.         for rows in self.execute_sql(MULTI):
File "/usr/lib/python2.4/site-packages/django/db/models/sql/query.py" in execute_sql
  1613.         cursor = self.connection.cursor()
File "/usr/lib/python2.4/site-packages/django/db/backends/__init__.py" in cursor
  56.         cursor = self._cursor(settings)
File "/usr/lib/python2.4/site-packages/django/db/backends/mysql/base.py" in _cursor
  221.             self.connection = Database.connect(**kwargs)
File "/usr/lib64/python2.4/site-packages/MySQLdb/__init__.py" in Connect
  74.     return Connection(*args, **kwargs)
File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py" in __init__
  198.         self.set_character_set(charset)
File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py" in set_character_set
  277.                 super(Connection, self).set_character_set(charset)

Exception Type: InterfaceError at /infocoll/admin/
Exception Value: (0, '')

comment:6 by khsing, 16 years ago

I use mod_python 3.3.1 and Apache 2.28

0> /data1/apache/bin/httpd -V -m
Server version: Apache/2.2.8 (Unix)
Server built:   Aug 13 2008 19:04:07
Server's Module Magic Number: 20051115:11
Server loaded:  APR 1.2.12, APR-Util 1.2.12
Compiled using: APR 1.2.12, APR-Util 1.2.12
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/data1/apache"
 -D SUEXEC_BIN="/data1/apache/bin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"
0> /data1/apache/bin/httpd -M
Loaded Modules:
 core_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 authz_host_module (shared)
 authz_user_module (shared)
 auth_basic_module (shared)
 auth_digest_module (shared)
 deflate_module (shared)
 log_config_module (shared)
 env_module (shared)
 mime_module (shared)
 cgi_module (shared)
 dir_module (shared)
 alias_module (shared)
 rewrite_module (shared)
 php4_module (shared)
 python_module (shared)
Syntax OK

comment:7 by Jacob, 16 years ago

Resolution: worksforme
Status: newclosed

I'm pretty sure this is a problem with your installtion of MySQL and/or MySQLdb. Since this isn't a bug in Django, please take this to django-users -- someone there will likely be able to point your in the right direction.

comment:8 by Yeago, 15 years ago

Its a general python problem with mysql 5.0

http://bugs.mysql.com/bug.php?id=21543

comment:9 by Jacob, 12 years ago

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top