Categories
Development MySQL Python SQL

insert data in RDS MySQL with python ( IndentationError: unindent does not match any outer indentation level)

I use RDS MySQL, and I want to insert data in a table with Python code, but I have the error

File "DB2.py", line 23
mySql_insert_query = """INSERT INTO empolyee (ID, Name, date) VALUES (1, 'reham', '2019-08-14')"""
IndentationError: unindent does not match any outer indentation level

the code

import mysql.connector
from mysql.connector import Error
from mysql.connector import errorcode


 try:
     connection = mysql.connector.connect(host="****",
                                     user="****",
                                     passwd="****",
                                     database="attendance1")

   if connection.is_connected():
      db_Info = connection.get_server_info()
      print("Connected to MySQL Server version ", db_Info)
      cursor = connection.cursor()
      cursor.execute("select database();")
      record = cursor.fetchone()
      print("You're connected to database: ", record)

except Error as e:
      print("Error while connecting to MySQL", e)

  mySql_insert_query = """INSERT INTO empolyee (ID, Name, date) VALUES (1, 'reham', '2019-08-14')"""

   cursor = connection.cursor()
   result = cursor.execute(mySql_insert_query)
   connection.commit()
   print("Record inserted successfully into Laptop table")
   cursor.close()

except mysql.connector.Error as error:
print("Failed to insert record into table {}".format(error))

finally:
   if (connection.is_connected()):
    connection.close()
    print("MySQL connection is closed")

Leave a Reply

Your email address will not be published. Required fields are marked *