MySQLdb problem with mod_python, please help

Discussion in 'Python' started by ws Wang, Nov 27, 2004.

  1. ws Wang

    ws Wang Guest

    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
     
    ws Wang, Nov 27, 2004
    #1
    1. Advertising

  2. ws Wang

    Damjan Guest

    Damjan, Nov 30, 2004
    #2
    1. Advertising

  3. ws Wang

    ws Wang Guest

    Damjan <> wrote in message news:<>...
    > > 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?req=show&file=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.
     
    ws Wang, Nov 30, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KK
    Replies:
    2
    Views:
    664
    Big Brian
    Oct 14, 2003
  2. scott

    Apache/mod_python & MySQLdb

    scott, Jan 13, 2005, in forum: Python
    Replies:
    0
    Views:
    313
    scott
    Jan 13, 2005
  3. Replies:
    2
    Views:
    440
  4. blbmdsmith
    Replies:
    1
    Views:
    669
    Graham Dumpleton
    Dec 14, 2006
  5. Cyril Bazin

    Problem with MySQLdb and mod_python

    Cyril Bazin, Jul 15, 2008, in forum: Python
    Replies:
    4
    Views:
    696
    Graham Dumpleton
    Jul 18, 2008
Loading...

Share This Page