很抱歉,如果您认为是重新发布,非常简单的代码,我怀疑这里也是一个微不足道的错误,但不能前进:
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")如前所述,怀疑微不足道的错误。有什么建议吗?提前谢谢
发布于 2014-05-13 14:44:49
您将获取的无名变量置于execute函数之外!
更改:
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()在剧本的末尾。
https://stackoverflow.com/questions/23633335
复制相似问题