0
我試圖得到查詢結果形式的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()
輸出我得到:
{ 「錯誤」: 「 '用戶'」}
爲什麼?我做錯了什麼?
謝謝。