Forums

pythonanywhere website db query return jsonify result

https://stackoverflow.com/q/45409510/8218480

I don't understand pythonanywhere website ,how to return json key value,but localhost only return value not key ??

env

1.flask

2.SQLAlchemy

3.mysql

4.python 2.7

my orm class

Base = declarative_base()
class DataEntity(Base):
      __tablename__ = 'data'
      id = Column("id", INTEGER, primary_key=True, nullable=False,autoincrement=True)
      clientid= Column("client_id", VARCHAR(32),nullable=False)
      name= Column("name", VARCHAR(10),nullable=False)
      description= Column("description", VARCHAR(20),nullable=False)

my flask_app.py

engine = create_engine('mysql+mysqldb://xxx:xxx@xxx.mysql.pythonanywhere-services.com/xxx$dbname?charset=utf8', echo=True,pool_recycle=280)
Session = sessionmaker(bind=engine)
dbsession = Session()

@app.route('/api/data')
def getdata():
    data = dbsession.query(DataEntity.id,DataEntity.name).all();
    return jsonify({'data': data})

pythonanywhere website json result

{"data": [{"id": 1,"name": "name1"},{"id": 2,"name": "name2"}]}

local json result

{"data": [[1,"name1"],[2,"name2"]]}

maybe it's a different version of sqlalchemy/flask etc?

Service info

Local info

Version Same

and which version of mysql are you using locally? we provide 5.6...

if that's the same then I'd suggest switching to using a virtualenv, just to be 100% sure that it's not something to do with some of the system-installed packages. more info here: http://help.pythonanywhere.com/pages/Virtualenvs