0

抱歉,如果您认为是转发,非常简单的代码,我怀疑这里也是一个微不足道的错误,但无法继续前进:

import whois
import MySQLdb
db = MySQLdb.connect(host="localhost", user="root",  passwd="pass", db="whois")
cur = db.cursor()
wi = whois.whois("google.com")
cur.execute("""INSERT INTO wrec (dname, wfull, dns) VALUES (%s, %s, %s)""") , (wi.domain_name, wi.text, wi.name_servers)

结束于:

_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 '%s, %s, %s)' at line 1")

如前所述,怀疑是微不足道的错误。有什么建议么?非常感谢提前

4

1 回答 1

1

您将获取的 Whois 变量放在了执行函数之外!

改变:

cur.execute("""INSERT INTO wrec (dname, wfull, dns) VALUES (%s, %s, %s)""") , (wi.domain_name, wi.text, wi.name_servers)

到:

cur.execute("""INSERT INTO wrec (dname, wfull, dns) VALUES (%s, %s, %s)""", (wi.domain_name, wi.text, wi.name_servers))

编辑:

不要忘记添加:

db.commit()

在脚本的末尾。

于 2014-05-13T14:44:49.963 回答