By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,741 Members | 2,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,741 IT Pros & Developers. It's quick & easy.

MySQLdb problem with mod_python, please help

P: n/a
MySQLdb is working fine at command line, however when I tried to use
it with mod_python, it give me a "server not initialized" error.

This is working fine:
----------------------- testmy.py -------------------------------
#!/usr/bin/python
import MySQLdb
db = MySQLdb.connect(host="localhost", user="root", passwd="mypass",
db="my_db")
cursor = db.cursor()
cursor.execute("SELECT * FROM parks")
result = cursor.fetchall()
for record in result:
print record[0] , "-->", record[1]
------------------------------------------------------------------
when I type "testmy.py", it give me correct results. (I run as root)

BUT,
This:
------------------ index.py --------------------
import sys, os, MySQLdb
from mod_python import apache
def handler(req):
sys.stdout = req
req.content_type = "text/html"
db = MySQLdb.connect(host="localhost", user="root",
passwd="mypass", db="my_db")
cursor = db.cursor()
cursor.execute("SELECT * FROM parks")
result = cursor.fetchall()
for record in result:
print record[0] , "-->", record[1]
return apache.OK
---------------------------------------------------

When I tried to open it from the browser, it give me following error
message:
--------------------------------------------------
Mod_python error: "PythonHandler index"

Traceback (most recent call last):

File "/usr/lib/python2.2/site-packages/mod_python/apache.py", line
299, in HandlerDispatch
result = object(req)

File "/var/www/html/index.py", line 6, in handler
db = MySQLdb.connect(host="localhost", user="root",
passwd="mypass", db="my_db")

File "/usr/lib/python2.2/site-packages/MySQLdb/__init__.py", line
64, in Connect
return apply(Connection, args, kwargs)

File "/usr/lib/python2.2/site-packages/MySQLdb/connections.py", line
116, in __init__
self._make_connection(args, kwargs2)

File "/usr/lib/python2.2/site-packages/MySQLdb/connections.py", line
41, in _make_connection
apply(super(ConnectionBase, self).__init__, args, kwargs)

InternalError: (-1, 'server not initialized')
-----------------------------------------------------------

My apache setting for mod_python is:
AddHandler mod_python .py
PythonHandler index
PythonDebug On

mod_python works on my site, if I replace the whole database stuff
with just (print "hello, world"), I get "hello, world" on the browser.
apache is run as "apache/apache"

What did I do wrong? (Is this a priviledge problem or something else?)

Any help is greatly appreciated.

Wensheng
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
> MySQLdb is working fine at command line, however when I tried to use
it with mod_python, it give me a "server not initialized" error.


Maybe its this problem?
http://www.modpython.org/FAQ/faqw.py...=faq02.013.htp

--
damjan
Jul 18 '05 #2

P: n/a
Damjan <gd*****@gmail.com> wrote in message news:<31*************@uni-berlin.de>...
MySQLdb is working fine at command line, however when I tried to use
it with mod_python, it give me a "server not initialized" error.


Maybe its this problem?
http://www.modpython.org/FAQ/faqw.py...=faq02.013.htp


yep! that's the culprit.

I havent' recompile php, but by removing loadmodule php, mod_python+mysql worked.

Thank you very much Damjan.
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.