I am currently having troubles inserting into MYSQL DB using python. The execute statement below dosen't run, which I found out using print stmts.
This is a mystery to me as while using the same codes, my friends are able to insert into their DB (Of course using the appropriate mysql host, password etc. and the same mysql and python version)
mycursor.execute("""
INSERT INTO emailcontent (Subject, Date, Sender, Sendee, Message_body)
VALUES (%(Subject)s, %(Date)s, %(Sender)s, %(To)s, %(Message_body)s)
""", temp_dict)
mydb.commit()
temp_dict example data:
{'Subject': 'Security alert', 'Date': '2020-12-28', 'Sender': 'Google <no-reply@accounts.google.com>', 'Snippet': 'Quickstart was granted access to your Google Account sometestemail@gmail.com If you did not grant access, you should check this activity and secure your account. Check activity You can also see security',
'To': 'sometestemail@gmail.com'}
Other codes:
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="root",
database="database"
)
mycursor = mydb.cursor()
Versions
Python 3.9.1
mysql 8.0.22
mysql-connector 2.2.9