python - got response 200 but nothing happen (flask-mysql) -


so follow tutorial, , after reach step connect python mysql, got 200 response code, on postman see this: { "error": "%d format: number required, not str" }

and check table on mysql, nothing happen, still empty. please me.

here code:

from flask import flask flask_restful import resource, api, reqparse flaskext.mysql import mysql  mysql = mysql() app = flask(__name__)  app.config['mysql_database_user'] = 'root' app.config['mysql_database_password'] = 'root' app.config['mysql_database_host'] = 'localhost' app.config['mysql_database_port'] = '5002' app.config['mysql_database_db'] = 'itemlistdb'  mysql.init_app(app)  api = api(app)  class createuser(resource):     def post(self):         try:             parser = reqparse.requestparser()             parser.add_argument('email', type=str, help='email address create user')             parser.add_argument('password', type=str, help='password create user')             args = parser.parse_args()              p_username = args['email']             p_password = args['password']              conn = mysql.connect()             cursor = mysql.get_db().cursor()             cursor.callproc('spcreateuser',(p_username,p_password))             data = cursor.fetchall()              if len(data) 0:                 conn.commit()                 return {'statuscode':'200','message': 'user creation success'}             else:                 return {'statuscode':'1000','message': str(data[0])}          except exception e:             return {'error': str(e)}  class authenticateuser(resource):     def post(self):         try:             parser = reqparse.requestparser()             parser.add_argument('email', type=str, help='email address authentication')             parser.add_argument('password', type=str, help='password authentication')             args = parser.parse_args()              p_username = args['email']             p_password = args['password']              conn = mysql.connect()             cursor = conn.cursor()             cursor.callproc('sp_authenticateuser',(p_username,))             data = cursor.fetchall()              if(len(data)>0):                 if(str(data[0][2])==p_password):                     return {'status':200,'userid':str(data[0][0])}                 else:                     return {'status':100,'message':'authentication failure'}          except exception e:             return {'error': str(e)}   api.add_resource(createuser, '/createuser') api.add_resource(authenticateuser, '/authenticateuser')  if __name__ == '__main__':     app.run(debug=true) 

screenshot error

i suspect issue isn't call create user, app connection itself.

specifically, wonder this:

app.config['mysql_database_port'] = '5002' 

server port numbers integers (this isn't python thing, it's architecture standard), when mysql tries connect, doing like:

'<rest-of-the-connection:%d' % app.config['mysql_database_port'] 

in case, though, app.config['mysql_database_port'] str, not int.

try

app.config['mysql_database_port'] = 5002 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -