- Server OS: Red Hat Enterprise Linux Server release 5.11
- Apache: 2.2.3
- Python: 2.7.6
- Mod_WSGI 4.5.3, Web.Py, MySQLdb
Hey! I have created a Web.Py site that queries data from a remote Oracle database which works perfectly, but I have now run into a problem when trying to create user authentication from a remote MySQL database.
Following the steps from here: http://webpy.org/cookbook/userauthpgsql
The exact same program works from the python commandline, but for some reason when trying to connect to the remote MySQL database from Apache, I get the following error:
<type 'exceptions.AttributeError'> at /login
'module' object has no attribute 'connect'
Things I've tried:
- List item
- Disabled SELinux
- Added permissions for apache@myserversIP to the MySQL.
- Tried both MySQLdb & web.database for the connection
- Googled a lot.
Here's the code that is being run from my main program:
myDB = MySQLdb.connect(host='ip',user='user',passwd='password',db='db',port=3306 );
cHandler = myDB.cursor()
cHandler.execute("SHOW TABLES;")
results = cHandler.fetchall()
for items in results:
print items
Any help regarding the issue, or ways to diagnose it further would be appreciated a lot! Thanks
Edit1: I checked where the MySQLdb is being searched from: /usr/local/lib/python2.7/site-packages
Which seems to be correct.
Edit2:
ldd mod_wsgi.so
linux-vdso.so.1 => (0x00007fff4b5fd000)
libpython2.7.so.1.0 => /lib64/libpython2.7.so.1.0
libpthread.so.0 => /lib64/libpthread.so.0
libdl.so.2 => /lib64/libdl.so.2
libutil.so.1 => /lib64/libutil.so.1
libm.so.6 => /lib64/libm.so.6
libc.so.6 => /lib64/libc.so.6
/lib64/ld-linux-x86-64.so.2
MySQLdb.__file__
? Are you sure you don't have a file laying around somewhere in your code calledMySQLdb.py
? – Graham Dumpletonsys.prefix
of/usr/local
for the Python version you want to use, that can be an immediate problem. Look at modwsgi.readthedocs.io/en/develop/user-guides/… and work out whatldd
on themod_wsgi.so
file shows. If it isn't using a Python shared library from/usr/local/lib
that can cause a problem. If you have Python 2.7.X in both system location and/usr/local
, you need to build mod_wsgi from source code with special steps so finds correct library. – Graham Dumpleton