title: How to return data from a MySQL query in a Flask app?
body: <p>I have the following code:</p>
  
  <pre><code>import flask as fk
  import MySQLdb
  import JSONEncoder
  
  
  class SpecializedJSONEncoder(JSONEncoder):
      def default(o):
          if isinstance(o, date):
              return date.strftime("%Y-%m-%d")
          else:
              super(SpecializedJSONEncoder, self).default(o)
  
  app = fk.Flask(__name__)
  app.json_encoder = SpecializedJSONEncoder
  app.debug = True
  
  @app.route("/")
  def home():
     return "Hello world"
  
  @app.route("/temp")
  def temp():
      db = MySQLdb.connect("localhost", "root", "","test")
      cur = db.cursor()
      query = "SELECT DATE(DTM), POM, ROUND(MIN(TMP),1) FROM dados_meteo WHERE POM = %s AND      DATE(DTM) &gt;= %s AND DATE(DTM) &lt;= %s"
      param = ("Faro", "2013-12-01", "2013-12-05")
      cur.execute(query, param)
      data = cur.fetchall()
  
      return data.json_encoder()
  
   if __name__ == "__main__":
      app.run()
  </code></pre>
  
  <p>The error returned is: ImportError: No module named JSONEncoder</p>