Edgewall Software
Modify

Opened 15 years ago

Closed 14 years ago

Last modified 4 years ago

#4459 closed defect (duplicate)

AttributeError: 'module' object has no attribute 'connect'

Reported by: robotronick@… Owned by: Christian Boos
Priority: normal Milestone:
Component: web frontend/mod_python Version: 0.10-stable
Severity: normal Keywords: mysql
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

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 (1)

mysql_import_fix-r5398.patch (1.4 KB ) - added by Christian Boos 15 years ago.
Potential fix for the issue, patch on latest trunk, which applies on 0.10-stable as well (ignore the failure for the second hunk)

Download all attachments as: .zip

Change History (26)

comment:1 by robotronick@…, 15 years ago

If I start trac as an Daemon it works properly…

comment:2 by Tim Hatch, 15 years ago

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 by robotronick@…, 15 years ago

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 by Matthew Good, 15 years ago

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 by robotronick@…, 15 years ago

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 by marcello, 15 years ago

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 by darwinye@…, 15 years ago

I do not want to remove the php5 apache module,so any one can give another solution to this problem?

in reply to:  7 comment:8 by Matthew Good, 15 years ago

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 by darwinye@…, 15 years ago

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

in reply to:  9 comment:10 by Matthew Good, 15 years ago

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 by Christian Boos, 15 years ago

Milestone: none

See also the probably related ticket #5012.

comment:12 by poetics5@…, 15 years ago

Summary: TypeError: object does not support item assignmentAttributeError: 'module' object has no attribute 'connect'
Version: 0.10.30.10-stable

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 by Christian Boos, 15 years ago

Keywords: needinfo added
Milestone: not applicable0.10.5
Owner: changed from Christopher Lenz to Christian Boos
Status: newassigned

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.

by Christian Boos, 15 years ago

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 by poetics5@…, 15 years ago

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'

in reply to:  14 comment:15 by Christian Boos, 15 years ago

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 by poetics5@…, 15 years ago

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 by poetics5@…, 15 years ago

FYI - I updated db/mysql_backend.py to the most recent trac svn version , and recompiled svn. this corrected the issue.

comment:18 by Christian Boos, 15 years ago

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 by poetics5@…, 15 years ago

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 by Christian Boos, 15 years ago

Well, as I said, there's no difference between that file and the one from the latest package:

Looks a bit weird to me. Let's see if the problem doesn't reappear after some time.

comment:21 by poetics5@…, 15 years ago

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 by Christian Boos, 14 years ago

Keywords: mysql added; needinfo removed
Milestone: 0.10.5
Resolution: duplicate
Status: assignedclosed

Seems to have been related to installation issues (see comment:6, comment:21 and #5012).

comment:23 by Christian Boos, 14 years ago

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).

comment:24 by geettha34@…, 4 years ago

I am receiving the following error while trying to connect to PostgreSQL. I've been struggling with this just one statement (which was working couple months before). Can someone help me fix this error.

AttributeError: module 'psycopg2' has no attribute 'connect' 
Last edited 4 years ago by Ryan J Ollos (previous) (diff)

in reply to:  24 comment:25 by Ryan J Ollos, 4 years ago

Replying to geettha34@…:

I am receiving the following error while trying to connect to PostgreSQL.

Please ask on the MailingList.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.