Apache doesn't probably run as any of the users which your database allows access to. Add lines in your CGI which says:
import os print os.getuid() and then see what user that UID actually is and give it access. User may be something like "apache", "www", "wwwroot" or possibly even "nobody" depending on the system configuration. You can also check your Apache configuration for lines: User www Group www to see what it runs as: Graham Firat KUCUK wrote .. > my distro is ubuntu breezy, > I used cgi handler. And text mime type > so i can view the print statement. > > MySQL server 4.0.24 > apache 2.0.54 > python2.4-mysqldb 1.2.1 > > php, console python, cgi python works fine. > > my .htaccess file > > Allow from All > > AddHandler mod_python .py > PythonHandler mod_python.cgihandler > PythonDebug On > > DirectoryIndex index.htm index.html index.php index.py index.pl > > ----------------------------------------------------------------------------- > > #! /usr/bin/python > # -*- coding: UTF-8 -*- > > print 'Content-Type: text/plain\n' > > import MySQLdb > conn = MySQLdb.connect( > host = '127.0.0.1', > user = 'pismikrop', > passwd = 'pass', > db = 'gate') > print conn > conn.close() > > > ------------------------------------------- > > output: > <_mysql.connection open to '(null)' at 82a97e4> > > > if host = '10.0.0.6' > > Mod_python error: "PythonHandler mod_python.cgihandler" > > Traceback (most recent call last): > > File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, > in HandlerDispatch > result = object(req) > > File "/usr/lib/python2.4/site-packages/mod_python/cgihandler.py", line > 96, in handler > imp.load_module(module_name, fd, path, desc) > > File "/home/pismikrop/vhosts/mikropyuvasi/content/tests/mpcgi/firat.py", > line 11, in ? > db = 'gate') > > File "/usr/lib/python2.4/site-packages/MySQLdb/__init__.py", line 66, > in Connect > return Connection(*args, **kwargs) > > File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line > 134, in __init__ > super(Connection, self).__init__(*args, **kwargs2) > > OperationalError: (2003, "Can't connect to MySQL server on '10.0.0.6' (111)") > > ------------------------------------------ > > mysql> SELECT User, Host FROM user; > +------------------+--------------+ > | User | Host | > +------------------+--------------+ > | pismikrop | % | > | debian-sys-maint | localhost | > | root | localhost | > | root | mikropyuvasi | > +------------------+--------------+ > > pismikrop user has all priviliges to all databases.