fedorp1 fedorp1 - 6 months ago 11
SQL Question

Python MySQLdb Query Returns "None"

I'm running the following code with web.py to get mysql data and print it out on a webpage. For some reason, when I query the webpage, I get just the word "None". Any idea what the problem is? There is some data in the MySQL database, the credentials are valid, and the code is running without any errors.

import web
import MySQLdb
import json
import collections

db=MySQLdb.connect(user="someuser",
passwd="somepass",db="somedatabase")

urls = (
'/', 'index',
'/test', 'test'
)


class index:
def GET(self):
c=db.cursor()
c.execute("""
SELECT email, password
FROM users
""")

rows = c.fetchall()


Screenshot

Answer

I think your code fragment may be either incomplete or misformatted, but assuming it is not, the GET method has no return statement, which means that any invocation would return None, which in turn would be rendered as the string "None"

Comments