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 に答える