鱼C论坛

 找回密码
 立即注册
查看: 2656|回复: 6

python mysql insert

[复制链接]
发表于 2016-5-12 10:45:48 | 显示全部楼层 |阅读模式
5鱼币
各位大大好~小弟使用python 寫入mysql時一直出現_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 ''sha1', 'resource', 'response_code', 'scan_date', 'sha256', 'positives', 'total'' at line 1")

原碼如下:
        a = str(json_response.get('sha1'))
        b = str(json_response.get('resource'))
        c = int(json_response.get('response_code'))
        d = str(json_response.get('scan_date'))
        e = str(json_response.get('sha256'))
        f = int(json_response.get('positives'))
        g = int(json_response.get('total'))
        h = str(json_response.get('md5'))
       
        conn = MySQLdb.connect(host, user, passwd, db)
        cur = conn.cursor()
        writelog = ("insert into vt_scan('sha1', 'resource', 'response_code', 'scan_date', 'sha256', 'positives', 'total', 'md5')values ('%s','%s', '%s', '%s', '%s', '%s', '%s', '%s')" % (a, b, c, d, e, f, g, h))
        cur.execute(writelog)
        conn.commit()

到底是錯在哪有哪位大大可以幫解決一下嗎?

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-5-13 15:08:12 | 显示全部楼层
不明白原因,刚进入学习PYTHON 阶段。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-5-16 08:57:35 | 显示全部楼层
加油
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-6-1 15:36:56 | 显示全部楼层
sql语句里面 字段名不用加引号的,
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-11-3 15:41:33 | 显示全部楼层
sql语句里面 字段名不用加引号的,insert into table_name (column_name1,column_name2,column_name3....)values(....)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-12-25 15:45:42 | 显示全部楼层

sql语句里面 字段名不用加引号的,
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-12-25 15:46:31 | 显示全部楼层
好像是这样
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-21 00:43

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表