Ticket #4459 (closed defect: duplicate)
AttributeError: 'module' object has no attribute 'connect'
| Reported by: | robotronick@… | Owned by: | cboos |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | web frontend/mod_python | Version: | 0.10-stable |
| Severity: | normal | Keywords: | mysql |
| Cc: |
Description
Hi,
I try to install trac 0.10.3 as mod_python method on Apache 2.0.54 and MySQL 5.0.30.
My Configuration is:
<Location /trac>
SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonOption TracEnv /var/www/trac
PythonDebug on
PythonOption TracUriRoot /trac
</Location>
I get this error:
Mod_python error: "PythonHandler trac.web.modpython_frontend"
Traceback (most recent call last):
File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
result = object(req)
File "/usr/lib/python2.3/site-packages/trac/web/modpython_frontend.py", line 87, in handler
gateway.run(dispatch_request)
File "/usr/lib/python2.3/site-packages/trac/web/wsgi.py", line 87, in run
response = application(self.environ, self._start_response)
File "/usr/lib/python2.3/site-packages/trac/web/main.py", line 377, in dispatch_request
env = _open_environment(env_path, run_once=run_once)
File "/usr/lib/python2.3/site-packages/trac/web/main.py", line 58, in _open_environment
env_cache[env_path] = open_environment(env_path)
File "/usr/lib/python2.3/site-packages/trac/env.py", line 435, in open_environment
if env.needs_upgrade():
File "/usr/lib/python2.3/site-packages/trac/env.py", line 313, in needs_upgrade
db = self.get_db_cnx()
File "/usr/lib/python2.3/site-packages/trac/env.py", line 182, in get_db_cnx
return DatabaseManager(self).get_connection()
File "/usr/lib/python2.3/site-packages/trac/db/api.py", line 75, in get_connection
return self._cnx_pool.get_cnx(self.timeout or None)
File "/usr/lib/python2.3/site-packages/trac/db/pool.py", line 101, in get_cnx
cnx = self._connector.get_connection(**self._kwargs)
File "/usr/lib/python2.3/site-packages/trac/db/mysql_backend.py", line 40, in get_connection
return MySQLConnection(path, user, password, host, port, params)
File "/usr/lib/python2.3/site-packages/trac/db/mysql_backend.py", line 143, in __init__
host=host, port=port, use_unicode=True)
File "/usr/lib/python2.3/site-packages/MySQLdb/__init__.py", line 66, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line 151, in __init__
self.converter[types.StringType] = string_literal
TypeError: object does not support item assignment
Regards, Axel
Attachments
Change History
comment:2 Changed 4 years ago by thatch
The error appears to be in the MySQLdb extension. I checked the source and self.converter is initialized to a dict in the latest (1.2.1p2) so it ought to be working (so I'm inclined to say it's a bug in either your system installation or in MySQLdb). Can you verify that you're loading the same MySQLdb from console?
$ python >>> import MySQLdb >>> print MySQLdb.__file__ /usr/lib/python2.3/site-packages/MySQLdb/__init__.py
comment:3 Changed 4 years ago by robotronick@…
Here the output. It seem's to be the same MySQLdb...
Python 2.3.5 (#2, Oct 16 2006, 19:19:48) [GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb >>> print MySQLdb.__file__ /usr/lib/python2.3/site-packages/MySQLdb/__init__.pyc
Our version of MySQLdb is 1.2.1c2
comment:4 Changed 4 years ago by mgood
Is it possible for you to upgrade to the final MySQLdb 1.2.1 release? 1.2.1c2 was an early pre-release and may contain bugs.
comment:5 Changed 4 years ago by robotronick@…
Sorry, but now it is not possible for me to upgrade to the final MySQLdb release. Now I am running Trac as CGI-Modul without any problems.
Thanks, Axel
comment:6 Changed 4 years ago by marcello
I had a similar (identical ?) error which was fixed by removing the php5 apache modules. The main issue seems to be a conflict between libmysqlclient_r.so.12 (used by _mysql.so in python site-packages) and libmysqlclient.so.14 (used by php5).
Running on debian, where mysqldb 1.2.1c2 is the latest stable, I couldn't find a way to have the two modules running together. I would say it's not a trac problem.
Hope it helps, regards.
comment:7 follow-up: ↓ 8 Changed 4 years ago by darwinye@…
I do not want to remove the php5 apache module,so any one can give another solution to this problem?
comment:8 in reply to: ↑ 7 Changed 4 years ago by mgood
Replying to darwinye@gmail.com:
I do not want to remove the php5 apache module,so any one can give another solution to this problem?
The easiest solution is to switch from mod_python to FastCGI. Otherwise you'll need to recompile PHP or the Python MySQL driver so they link to the same MySQL library.
comment:9 follow-up: ↓ 10 Changed 4 years ago by darwinye@…
I am not using trac with mysqldb, I just want to write a webpage with python+mysql. so the only solution is the second. Can you give me any idea about how to recompile the python or php mysql driver. whether the driver is the _mysql.so ?
thx
comment:10 in reply to: ↑ 9 Changed 4 years ago by mgood
Replying to darwinye@gmail.com:
I am not using trac with mysqldb, I just want to write a webpage with python+mysql.
Then this is off-topic for this ticket. You can try the MailingList (prefix your message with "OT:" since it's off-topic for Trac), or check the appropriate support lists or forums for PHP or MySQLdb.
comment:11 Changed 3 years ago by cboos
- Milestone set to none
See also the probably related ticket #5012.
comment:12 Changed 3 years ago by poetics5@…
- Version changed from 0.10.3 to 0.10-stable
- Summary changed from TypeError: object does not support item assignment to AttributeError: 'module' object has no attribute 'connect'
Hi everyone, i'm trying to setup trac on a media temple vps setup (centos, plesk) using mysql as the backend. i'm using what ever is the stable version of trac (just downloaded today)
I've receiving a similar error - from apache error log:
Traceback (most recent call last): PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in HandlerDispatch\n result = object(req) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/web/modpython_frontend.py", line 87, in handler\n gateway.run(dispatch_request) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/web/wsgi.py", line 87, in run\n response = application(self.environ, self._start_response) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/web/main.py", line 391, in dispatch_request\n env = _open_environment(env_path, run_once=run_once) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/web/main.py", line 58, in _open_environment\n env_cache[env_path] = open_environment(env_path) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/env.py", line 463, in open_environment\n if env.needs_upgrade(): PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/env.py", line 341, in needs_upgrade\n db = self.get_db_cnx() PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/env.py", line 203, in get_db_cnx\n return DatabaseManager(self).get_connection() PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/db/api.py", line 76, in get_connection\n return self._cnx_pool.get_cnx(self.timeout or None) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/db/pool.py", line 101, in get_cnx\n cnx = self._connector.get_connection(**self._kwargs) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/db/mysql_backend.py", line 40, in get_connection\n return MySQLConnection(path, user, password, host, port, params) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/db/mysql_backend.py", line 146, in __init__\n cnx = MySQLdb.connect(db=path, user=user, passwd=password, PythonHandler trac.web.modpython_frontend: AttributeError: 'module' object has no attribute 'connect'
comment:13 Changed 3 years ago by cboos
- Keywords needinfo added
- Owner changed from cmlenz to cboos
- Status changed from new to assigned
- Milestone changed from not applicable to 0.10.5
Can you please apply the patch in #5012 which will help to better understand the problem? Thanks.
After that, you can try the following attachment:mysql_import_fix-r5398.patch which will probably fix the issue.
Changed 3 years ago by cboos
- attachment mysql_import_fix-r5398.patch added
Potential fix for the issue, patch on latest trunk, which applies on 0.10-stable as well (ignore the failure for the second hunk)
comment:14 follow-up: ↓ 15 Changed 3 years ago by poetics5@…
I've applied the 5012 patch and here is the output from the apache log.
I'll make a backup of this file and try your 5398 patch
PythonHandler trac.web.modpython_frontend: Traceback (most recent call last): PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in HandlerDispatch\n result = object(req) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/web/modpython_frontend.py", line 87, in handler\n gateway.run(dispatch_request) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/web/wsgi.py", line 87, in run\n response = application(self.environ, self._start_response) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/web/main.py", line 391, in dispatch_request\n env = _open_environment(env_path, run_once=run_once) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/web/main.py", line 58, in _open_environment\n env_cache[env_path] = open_environment(env_path) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/env.py", line 463, in open_environment\n if env.needs_upgrade(): PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/env.py", line 341, in needs_upgrade\n db = self.get_db_cnx() PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/env.py", line 203, in get_db_cnx\n return DatabaseManager(self).get_connection() PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/db/api.py", line 76, in get_connection\n return self._cnx_pool.get_cnx(self.timeout or None) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/db/pool.py", line 101, in get_cnx\n cnx = self._connector.get_connection(**self._kwargs) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/db/mysql_backend.py", line 40, in get_connection\n return MySQLConnection(path, user, password, host, port, params) PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/db/mysql_backend.py", line 146, in __init__\n cnx = MySQLdb.connect(db=path, user=user, passwd=password, PythonHandler trac.web.modpython_frontend: AttributeError: 'module' object has no attribute 'connect'
comment:15 in reply to: ↑ 14 Changed 3 years ago by cboos
Replying to poetics5@yahoo.com:
I've applied the 5012 patch and here is the output from the apache log.
Ah, yes, well, the print won't be visible in this case... Could you please try this one instead?
Index: mysql_backend.py
===================================================================
--- mysql_backend.py (revision 5398)
+++ mysql_backend.py (working copy)
@@ -23,6 +23,7 @@
_like_escape_re = re.compile(r'([/_%])')
+from mod_python import apache
class MySQLConnector(Component):
"""MySQL database support for version 4.1 and greater.
@@ -44,6 +45,8 @@
cnx = MySQLConnection(path, user, password, host, port, params)
if not self._version:
import MySQLdb
+ apache.log_error('get_connection %r' % MySQLdb,
+ apache.APLOG_WARNING)
self._version = get_pkginfo(MySQLdb).get('version',
MySQLdb.__version__)
mysql_info = 'server: "%s", client: "%s", thread-safe: %s' % \
@@ -145,6 +148,7 @@
def __init__(self, path, user=None, password=None, host=None,
port=None, params={}):
import MySQLdb
+ apache.log_error('__init__ %r' % MySQLdb, apache.APLOG_WARNING)
if path.startswith('/'):
path = path[1:]
comment:16 Changed 3 years ago by poetics5@…
I made the changes and heres the output from apache's log this is without me applying your patch.
thank you for the help.
PythonHandler trac.web.modpython_frontend: Traceback (most recent call last):
PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in HandlerDispatch\n result = object(req)
PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/web/modpython_frontend.py", line 87, in handler\n gateway.run(dispatch_request)
PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/web/wsgi.py", line 87, in run\n response = application(self.environ, self._start_response)
PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/web/main.py", line 391, in dispatch_request\n env = _open_environment(env_path, run_once=run_once)
PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/web/main.py", line 58, in _open_environment\n env_cache[env_path] = open_environment(env_path)
PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/env.py", line 462, in open_environment\n env = Environment(env_path)
PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/env.py", line 142, in __init__\n load_components(self)
PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/loader.py", line 140, in load_components\n __import__(module)
PythonHandler trac.web.modpython_frontend: File "/usr/lib/python2.3/site-packages/trac/db/mysql_backend.py", line 48
PythonHandler trac.web.modpython_frontend: apache.log_error('get_connection %r' % MySQLdb,
PythonHandler trac.web.modpython_frontend: ^
PythonHandler trac.web.modpython_frontend: SyntaxError: invalid syntax
comment:17 Changed 3 years ago by poetics5@…
FYI - I updated db/mysql_backend.py to the most recent trac svn version , and recompiled svn. this corrected the issue.
comment:18 Changed 3 years ago by cboos
Well, there's been no changes in that file between the latest stable release (0.10.4) which you've stated you used, and the latest 0.10-stable svn revision.
Was this with or without the attachment:mysql_import_fix-r5398.patch?
Or did you rather update to the latest MySqlDb?
comment:19 Changed 3 years ago by poetics5@…
cboos once again thanx for your help
I already had the most recent version of mysqldb installed and this was a fresh install
I applied the code you posted, but did not apply the r5398 patch.
I then followed the suggestion here : http://trac.edgewall.org/ticket/3706#comment:10 and rebuild svn
Still had errors so I decided to grab a new copy of mysql_backend.py from http://trac.edgewall.org/browser/trunk/trac/db/mysql_backend.py
Once i installed the new file trac worked this morning i grabbed another copy of mysql_backend.py from http://trac.edgewall.org/browser/branches/0.10-stable/trac/db/mysql_backend.py and that is working as well.
comment:20 Changed 3 years ago by cboos
Well, as I said, there's no difference between that file and the one from the latest package:
- diff:branches/0.10-stable/trac/db/mysql_backend.py//tags/trac-0.10.4/trac/db/mysql_backend.py
- unless you had the 0.10.3 release (or 0.10.3.1): diff:branches/0.10-stable/trac/db/mysql_backend.py//tags/trac-0.10.3/trac/db/mysql_backend.py but even in this case, the change looks unrelated.
Looks a bit weird to me. Let's see if the problem doesn't reappear after some time.
comment:21 Changed 3 years ago by poetics5@…
I downloaded the most current stable release of 10.4 yesterday, and also all versions of the requires programs were the current versions as of yesterday. I think it may in art have been related to the issue addressed here : http://trac.edgewall.org/ticket/3706#comment:10?
As after rebuilding svn as described here and downloading mysql_backend.py i was fine.
If the issue reappears i'll be sure to post, and update this ticket with what resolves it.
thanks again for all your help
comment:22 Changed 3 years ago by cboos
- Keywords mysql added; needinfo removed
- Status changed from assigned to closed
- Resolution set to duplicate
- Milestone 0.10.5 deleted
Seems to have been related to installation issues (see comment:6, comment:21 and #5012).
comment:23 Changed 3 years ago by cboos
r6510 / r6511 contained a change similar to attachment:mysql_import_fix-r5398.patch.
I believe "local" imports are problematic, for some reason (see also #4280).



If I start trac as an Daemon it works properly...