Barry Pearce yazmış:
One extra comment on this...

Firstly make sure you have upgraded to the latest version of MySQLdb - we found earlier versions less than great.

Warning: If you have PHP installed it uses mysql client libraries which are OUT OF DATE - and will cause failures. Remove the php module from the server and try again.


We use MySQL 4.1 servers quite happily from mod_python under both win32 and linux.
  


Deron Meranda wrote:
On 4/12/06, Firat KUCUK <[EMAIL PROTECTED]> wrote:
  
conn = MySQLdb.connect(
           host   = '127.0.0.1',
           user   = 'pismikrop',
           passwd = 'pass',
           db     = 'db')
    

Unrelated to your question, but I see this a lot.  You should
not hardcode the database password in your script.  If your
script ever fails you may end up with a Python traceback, and
if PythonDebug is enabled (or you're using a framework on
top of mod_python) parts of your source code could be
dumped across the HTML output, including your password!

In web scripts, you should always read any passwords, etc.,
from some other place such as a file.

pw = open('.htdbpass','r').readline().strip()
conn = MySQLdb.connect(
            host   = '127.0.0.1',
            user   = 'pismikrop',
            passwd = pw,
            db     = 'db')
--
Deron Meranda

  
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.

Reply via email to