Python MySQLdb 查询 Returns "None"
Python MySQLdb Query Returns "None"
我 运行 下面的代码与 web.py 一起获取 mysql 数据并将其打印在网页上。出于某种原因,当我查询网页时,我只得到 "None" 这个词。知道问题是什么吗? MySQL数据库中有一些数据,凭据有效,代码运行没有任何错误。
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()
我认为您的代码片段可能不完整或格式错误,但假设不是,GET
方法没有 return 语句,这意味着任何调用都会 return None
,这又将呈现为字符串
"None"
我 运行 下面的代码与 web.py 一起获取 mysql 数据并将其打印在网页上。出于某种原因,当我查询网页时,我只得到 "None" 这个词。知道问题是什么吗? MySQL数据库中有一些数据,凭据有效,代码运行没有任何错误。
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()
我认为您的代码片段可能不完整或格式错误,但假设不是,GET
方法没有 return 语句,这意味着任何调用都会 return None
,这又将呈现为字符串
"None"