I have a flask app which is needed to insert data to db table which is mysql , so whatever port or host i give it is throwing me error like below .
mysql.connector.errors.InterfaceError
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'localhost:8016' (10061 No connection could be made because the target machine actively refused it)
So here is my code :
from flask import Flask
from flask import jsonify
import mysql.connector
app = Flask(__name__)
@app.route('/')
def hello():
print("Just go inside ")
return 'Atlast got inside Page'
@app.route('/insertdataToDBFile/<dbname>')
def writetodbfile(dbname):
'''mydb = mysql.connector.connect(
host="localhost",
user="root",
password=""
)
mycursor = mydb.cursor()
mycursor.execute("CREATE DATABASE IF NOT EXISTS "+dbname)'''
print("before connect")
mydb = mysql.connector.connect(
host="localhost",
port="8016",
user="root",
password="",
database = dbname
)
mycursor = mydb.cursor()
'''mycursor.execute("CREATE TABLE IF NOT EXISTS Issues (name VARCHAR(255), address VARCHAR(255))")'''
print("before Insert")
sql = "INSERT INTO Issue VALUES('Hi;llos','20120618 10:34:09 AM','kl','prod','20120618 10:34:09 AM','yes','yes','20120618 10:34:09 AM','yes','123','poem')"
mycursor.execute(sql)
mydb.commit()
return (str(mycursor.rowcount) + " record inserted.")
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8015, debug=True)
Since DB and Table is already created i commented out those lines . it is currently deployed inside Windows remote server and also it prints before connect on to console . I don know whether that is the reason . Can anyone help me to figure out why this is happening