0
votes
  • 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:

  1. List item
  2. Disabled SELinux
  3. Added permissions for apache@myserversIP to the MySQL.
  4. Tried both MySQLdb & web.database for the connection
  5. 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

1
What do you get if you log value of MySQLdb.__file__? Are you sure you don't have a file laying around somewhere in your code called MySQLdb.py?Graham Dumpleton
Hey Graham! When running through Apache, it's empty and when running from cmdline it's /usr/local/lib/python2.7/site-packages/MySQLdb/__init__.pyc I'm also sure that I don't have another file with the name MySQLdb.pyCatManJoe
Provide your mod_wsgi configuration? Check what version of Python mod_wsgi is compiled for? Possibly it isn't compiled for your Python 2.7 installation and that is causing all the issues. See modwsgi.readthedocs.io/en/develop/user-guides/…Graham Dumpleton
sys.version = '2.7.6 (default, Jun 28 2016, 15:58:57) \n[GCC 4.1.2 20080704 (Red Hat 4.1.2-55)]' sys.prefix = '/usr/local' Python version seems to be correct. This is a dumb question, but I'm unable to find wsgi.conf. It's not in /etc/httpd/conf.d/wsgi.conf and locate is unable to find it.CatManJoe
If you have sys.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 what ldd on the mod_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

1 Answers

0
votes

As has been commented, check to see if there is a file within the same directory as the file you're trying to run, that has the name MySQLdb.py