I'm running a flask web framework tied in to a sqlite databade. I'm having an issue returning a query that includes both the column name and the value of that column. I'm including the relevant code below.
import threading
import time
import KeySys
import serial
from flask import Flask, request
from flask_restful import reqparse, abort, Api, Resource
from sqlalchemy import create_engine
from json import dumps
from time import sleep
from datetime import datetime
e = create_engine('sqlite:///lockdb.db')
app = Flask(__name__)
api = Api(app)
parser = reqparse.RequestParser()
parser.add_argument('LockSwitch')
class Keystat_Meta(Resource):
def get(self):
#Connect to databse
conn = e.connect()
#Perform query and return JSON data
query = conn.execute('select * from LockStat')
return {'KeyStat': [query.cursor.fetchall()]} # I've tried keys() all() items(column, value) and various different queries.
api.add_resource(Keystat_Meta, '/keystat')
if __name__ == '__main__':
app.run()
queryshould be a dictionary according to the sqlalchemy docs. Try printingquery.items()to see if you're getting results.