0

I am trying to insert a data in MySQLdb when a condition accomplish, but never do that and jump to the except db.rollback(). which is my mistake? .Thanks

import MySQLdb
if __name__ == '__main__':
try:
    db=MySQLdb.connect("localhost","root","test","objects_ingresed")
    c= db.cursor()
    print("success conection")
except:
    print ("cant conect to server...")
if dA >= 62 and dA <= 71:
            if dB >= 43 and dB <= 50:

                    sql =  """INSERT INTO objects (cut_disc) VALUES(1)"""
                    try:
                            c.execute(sql)
                            db.commit()
                            print("data inserted")
                    except:
                            db.rollback()
                            print("data NO inserted")
  • Could you post the result of running `describe objects;` on your database? It would be good to verify that there is a column called `cut_disc` that would accept `1` as a legal value. – Andrew Merrill Dec 21 '19 at 03:26
  • 2
    Add a `raise` to your except block to see the actual exception. – Klaus D. Dec 21 '19 at 03:33
  • Print the exception (like this https://stackoverflow.com/questions/1483429/how-to-print-an-exception-in-python). You will then know what the issue is. – Nic3500 Dec 21 '19 at 03:35
  • This error appears: 'numpy.ndarray' object has no attribute 'execute'. What happens is that I am using open cv and what I want to do is that when the condition is met, write a data in the database, indicating that this image was recognized or something – alexis valderrama Dec 23 '19 at 00:11

0 Answers0