Python MySQL statement error, please help!
Hello everyone!
I always believed i am good in Python until this morning; a course mate came to my room with his laptop and presented me a code. It is simple Python MySQL statement returning an error.
I have tried to debug it, made a few changes but still it is not running.
Here is my final code after editing.
import os
import MySQLdb
import time
db = MySQLdb.connect(host="localhost", user="root", passwd="********", db="workspace")
cursor = db.cursor()
tailoutputfile = os.popen('tail -f syslog.log')
while 1:
    x = tailoutputfile.readline() Â
    if len(x)==0:
        break
    y = x.split()
    if y[2] == 'BAD':
        timestring = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
        cursor.execute("INSERT INTO releases (date, cat, name) values (timestring, y[4], y[7]")
    if y[2] == 'GOOD':
        print y[4] + 't' + y[7]
This was the error message i got after trying to run the code
user@machine:~/$ python reader.py
Traceback (most recent call last):
 File "reader.py", line 17, in ?
  cursor.execute("INSERT INTO releases (date, cat, name) values (timestring, y[4], y[7]")
 File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line 163, in execute
  self.errorhandler(self, exc, value)
 File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line 35, in defaulterrorhandler
  raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to                                your MySQL server version for the right syntax to use near '[4], y[7]' at line 1")
user@machine:~/$
Â
I am going nuts.
I can't find a solution to this. Please help me.