472,374 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

MySQLdb problem with mod_python, please help

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
2 2089
> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Nikolaidis | last post by:
Greetings, I am attempting to get MySQLdb 0.9.2 installed on Mac OS 10.2 with a Fink distribution of Python 2.2.2. I have seen only a few posts on the subject, some of them relate to...
2
by: Tim Williams | last post by:
I'm trying to write a simple python program to access a MySQL database. I'm having a problem with using MySQLdb to get the results of a SQL command in a cursor. Sometimes the cursor.execute works,...
2
by: Daniel Baggott | last post by:
Hi, I'm seeking assistance in troubleshooting connecting to MySQL (4.0.20) using Python (2.3.4) and MySQLdb (1.0.0). When I attempt to make a connection, I get the following exception:...
0
by: scott | last post by:
AIUI, global variables are supposed to be preserved within each Apache thread/prcoess. However, I'm importing and using MySQLdb within a class in a separate module, which is in turn imported and...
3
by: David Mitchell | last post by:
Hello, I am a complete beginner with Python. I've managed to get mod_python up and running with Apache2 and I'm trying to a simple insert into a table in a MySQL database. I'm using the...
2
by: Mondal | last post by:
Hi, I am using MySQL 5.0 beta and Active Python 2.4. I have the correct version of MySQLdb installed. The problem is that I can't connect to MySQL through the Active Python interactive window. ...
1
by: shearichard | last post by:
Hi - I have written some python to insert a row into a table using MySQLDB. I have never before written SQL/Python using embedded parameters in the SQL and I'm having some difficulties. Could...
3
by: joe jacob | last post by:
I configured apache to execute python scripts using mod_python handler. I followed below mentioned steps to configure apache. 1. In http.conf I added <Directory...
3
by: Lawrence D'Oliveiro | last post by:
In message <mailman.109.1216158151.922.python-list@python.org>, Cyril Bazin wrote: What's the error message? This should be in Apache's error_log file.
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.