I'm trying to set up a python program to edit a database from input from my arduino, and the try: command is giving me an error and I'm not sure I understand why
import serial
import MySQLdb
dbConn = MySQLdb.connect("localhost","root","Mecool100","ISEF_DB") or die ("Could not connect to database")
cursor = dbConn.cursor()
device = '/dev/ttyACM0'
try:
print "Trying...",device
arduino = serial.Serial(device, 250000)
except:
print "Failed to connect on",device
try:
data = arduino.readline() #read data
pieces = data.split("\t")
try:
cursor.execute("UPDATE `ISEF_DB`.`attendance` SET `present`='1' WHERE `id` = data”)
dbConn.commit()
cursor.close()
except MySQLdb.IntegrityError:
print "Failed to insert data"
finally:
cursor.close()
except:
print "Failed to get data"
This code is returning the following error:
File "test.py", line 21
try:
^
SyntaxError: invalid syntax
Could someone please assist me in finding my error?
Thank you :)
exceptclause after our previous linepieces = data.split("\t")trywithout anexcept/else/finally.