我试图从mysql中获取查询结果。
def on_get(self, req, resp):
try:
db = MySQLdb.connect(**db_conf.dbConfig)
#use dictionary cursor
cursor = db.cursor(MySQLdb.cursors.DictCursor)
q = ("select * from BUDGET")
cursor.execute(q)
rows = cursor.fetchall()
#init the output object
output = {'budget': []}
for row in rows:
data = {
"id_budget": row['id_budget'],
"amount": row['amount'],
"days": row['days'],
"user_id": row['user']
}
output['budget'].append(data)
resp.status = falcon.HTTP_200
resp.body = json.dumps(output, encoding='utf-8')
cursor.close()
db.close()
我得到的输出:
{“错误”:“‘用户’”}
为什么?我做错了什么?
谢谢你。