[mod_python] Dies on Database connection?

Ross M Karchner ross at karchner.com
Thu Jan 22 15:23:48 EST 2004


Manfred Stienstra wrote:

>On Thu, 2004-01-22 at 15:37, Ross M Karchner wrote:
>  
>
>>In mozilla, it loads a blank page, on Safari, I get a "page returned no 
>>data" error.
>>    
>>
>
>This is because you're not returning any data...
>  
>
Sure I am. This is just the simplest case I could make to illustrate the 
problem.

If I comment the C.execute line our, the word "something" is returned.

Here it is: http://localfeeds.com/near/display-rss-fixed.app

Calling "execute" on the cursor object breaks the script.

>>The code in display-rss.py is:
>>-------------------------------
>>DB = "db"
>>USER = "user"
>>PASS = "password"
>>
>>import MySQLdb
>>
>>def index(req):
>>   
>>    DB_CONN = MySQLdb.connect(db=DB, user=USER, passwd=PASS)
>>    C=DB_CONN.cursor()
>>    C.execute('select * from cities where id=17;')
>>    return "Something"
>>    
>>
>
>Maybe you should try something like this:
>
>
>DB = "db"
>USER = "user"
>PASS = "password"
>
>import MySQLdb
>from mod_python import apache
>
>def index(req):
>   
>    DB_CONN = MySQLdb.connect(db=DB, user=USER, passwd=PASS)
>    C=DB_CONN.cursor()
>    try:
>      C.execute('select * from cities where id=17;')
>      for row in c.fetchall():
>        req.write(str(row))
>      return apache.OK
>    finally:
>      C.close()
>      DB_CONN.close()
>
>  
>
I uploaded this script (adding the correct name and password) to 
http://localfeeds.com/near/manfred-test.app

'select * from cities where id=17;' returns exactly one row.


Thanks, everyone,  for your assistance so far-

-Ross


More information about the Mod_python mailing list