How do I display the results of my database query out in CocoaRestClient using python flask?
Here's the code:
import json
import sys
import datetime
import MySQLdb as mdb
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/home')
def hello_world():
return "Welcome to Omnimoda."
@app.route('/items/list')
def get_items():
#Change accordingly:
#Connection Details:
hostname = "localhost"
username = "un"
password = "pw"
database = "db"
q_list_one = "SELECT * FROM item_info"
con = mdb.connect(hostname, username, password, database)
cur = con.cursor()
json_return = {}
try:
cur.execute(q_list_one)
r_list_one = cur.fetchall()
except Error as error:
print(error)
finally:
cur.close()
con.close()
return jsonify(r_list_one)
if __name__ == '__main__':
app.run(host = '0.0.0.0', debug=True)
I got the jsonify
bit from here, but all I'm getting is a ValueError: dictionary update sequence element #0 has length 6; 2 is required
(full error traceback here)
Without the jsonify
, I get a TypeError: 'tuple' object is not callable
.
Here's what the database looks like:
Anything else I can try? Thanks.