python mysql返回_Python MySQL语句返回E

嘿,我对这一切都很陌生,所以请原谅我的愚蠢:)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]

所以我运行程序,这是我收到的错误消息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:~/$

所以我假设错误显然来自于SQL语句cursor.execute("INSERT INTO releases (date, cat, name) values (timestring, y[4], y[7]")

这里有一个y[4]和y[7]的例子。YES Mail.Sent.To.User:user@work.com.11.2.2008:23.17

发生此错误是因为我应该在尝试将这些值插入数据库之前对其进行转义吗?

或者我完全没有抓住重点??

任何帮助都将不胜感激!

提前谢谢。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值