I want to migrate my currently working rest APIs from backand.com to pythonanywhere that is created by flask framework.
Backand.com MySQL
SELECT `Trade` AS trade, COUNT(*) AS count
FROM `KLSE`
GROUP BY `Trade`
Flask_app.py
from flask import Flask,jsonify,abort,make_response
import MySQLdb
import MySQLdb.cursors
app = Flask(__name__)
@app.route('/KLSEstats', methods=['GET'])
def KLSEstats(Trade):
db = MySQLdb.connect(host='vinuk.mysql.pythonanywhere-services.com',user='user',passwd='xxx',db='vinusdb$default',cursorclass=MySQLdb.cursors.DictCursor)
curs = db.cursor()
try:
curs.execute("SELECT Trade ,COUNT(*) FROM KLSE GROUP BY Trade")
e = curs.fetchall()
except Exception:
return 'Error: unable to fetch items'
#return "hihi"
return jsonify({'Trade': e})
Unfortunately, it returns 500 internal server error My full json table is in this link
curs.execute("SELECT Trade FROM KLSE")
Trying above command also return 500 error. I know the command I use is not correct. I wanted to count the total of the BUY,SeLL,HOLD in the MySQL database table. I know there are some differences using mySQLdb module but unable to find more example so that I can convert mySQL language to Python.