0

i am trying to connect the database mysql using flask-python . i create a 'users' name table have two columns 'fname' 'lname' datatype string in my database name 'login'

code

  from flask import Flask
  from flask_mysqldb import MySQL
  app=Flask(__name__)
  app.config['MYSQL_HOST']='localhost'
  app.config['MYSQL_PORT']='3306'
  app.config['MYSQL_USER']='root'
  app.config['MYSQL_PASSWORD']='12345'
  app.config['MYSQL_DB']='login'
  mysql=MySQL(app)
  @app.route('/insert')
  def insert():
   fname="arslan" 
   lname="arshad"
   cur=mysql.connection.cursor()
   cur.execution("INSERT INTO users(fname,lname) VALUES(%s,%s)",(fname,lname))
   mysql.connection.commit()
   cur.close()
   return "inserted"
  app.run(debug=True)

ERROR:

TypeError TypeError: 'str' object cannot be interpreted as an integer

1
  • You are passing the port as a string. Does it happen to actually need be an integer? Commented Jul 20, 2022 at 15:50

1 Answer 1

1

I find my Error, i was using string value ..

  app.config['MYSQL_PORT']='3306' ##wrong
  app.config['MYSQL_PORT']=3306 ##correct

function accept a integer value so error show TypeError: 'str' object cannot be interpreted as an integer

Sign up to request clarification or add additional context in comments.

Comments

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.