Question

sorry if you consider as repost, quite simple code and i suspect also a trivial error here, but can't move forward:

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)

ends up in:

_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")

as said, suspecting trivial error. any suggestions? thanks a lot in advance

Was it helpful?

Solution

You placed the fetched Whois variables outside the execute function!

Change:

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

To:

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

Edit:

And don't forget to add:

db.commit()

at the end of the script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top