473,574 Members | 2,665 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="localhos t", 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_typ e = "text/html"
db = MySQLdb.connect (host="localhos t", 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: "PythonHand ler 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="localhos t", user="root",
passwd="mypass" , db="my_db")

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

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

File "/usr/lib/python2.2/site-packages/MySQLdb/connections.py" , line
41, in _make_connectio n
apply(super(Con nectionBase, 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 2184
> 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+mysq l 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
2578
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 "conflicting header files," but I don't know what to do about conflicting header files, or where I would find them, and once I found them, which ones to...
2
5038
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, sometimes not. From mysql: mysql> show databases; +-----------+ | Database |
2
2525
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: _mysql_exceptions.InternalError: (-1, 'server not initialized') The database is definitely running as I can connect to it using the mysql client. Also,...
0
1069
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 used within a _function (ie. not "published"). So, AFAICT, it's not supposed to be preseved. But unless I specifically close() the database...
3
2498
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 MySQLdb library for connectivity. I can read from the database no problem, but when I do an insert, the value never gets added to the database, even...
2
4499
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. Here is a sample error: >>> c=MySQLdb.Connect(host='localhost',user='root',passwd='',db='shop',port=3306) Traceback (most recent call last):
1
7458
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 someone point me in the right direction please ? The python looks like this : import MySQLdb import MySQLdb.cursors conn =...
3
4930
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 "D:/softwares/Apache2.2/htdocs"> AddHandler mod_python .py PythonHandler mptest PythonDebug On </Directory>
3
1872
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.
0
8063
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7822
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectóplanning, coding, testing, and deploymentówithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3742
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3754
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2249
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1062
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.