1

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.

9
  • 500 internal server error doesn't say anything. Do python(3) init.py or whatever your filename is and post the actual error Commented Jan 1, 2017 at 13:39
  • run flask_app.py actually has no error Commented Jan 1, 2017 at 13:46
  • What I usually do is turn off apache and use the debugging server. Insert multiple print statements to locate where the error occurred and see If I can fix it. Commented Jan 1, 2017 at 13:50
  • turn off apache. Where to turn off in pythonanywhere? Commented Jan 1, 2017 at 13:53
  • 1
    PythonAnywhere dev here -- check out the error log (linked from the "Web" tab). That will have the details of any errors Flask is generating. Commented Jan 2, 2017 at 18:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.