Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > MySQLdb problem with mod_python, please help

Reply
Thread Tools

MySQLdb problem with mod_python, please help

 
 
ws Wang
Guest
Posts: n/a
 
      11-27-2004
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
 
Reply With Quote
 
 
 
 
Damjan
Guest
Posts: n/a
 
      11-30-2004
> 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
 
Reply With Quote
 
 
 
 
ws Wang
Guest
Posts: n/a
 
      11-30-2004
Damjan <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> > 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQLdb error - PLEASE SAVE ME! Ed Hotchkiss Python 0 09-17-2005 07:50 PM
need help with MySQLdb nephish@xit.net Python 4 06-30-2005 01:07 PM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
Importing MySQLdb module causes malformed header error.. pls help!!! Kiran B. Python 0 11-05-2003 01:52 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments