0

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

gejza
  • 3
  • 2

1 Answers1

1

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.

mikejoh
  • 1,377
  • 11
  • 18
  • thanks a lot, this worked, however i've smashed on another mysql error. thanks once again – gejza May 13 '14 at 19:15
  • just to complete the code, the next error is about formatting. i found out that before inserting into mysql i need to transform the variables using str(). then it looks like this import whois import MySQLdb db = MySQLdb.connect(host="localhost", user="root", passwd="pass", db="whois") cur = db.cursor() wi = whois.whois("google.com") domname = str(wi.domain_name) fullwhois = str(wi.text) dnsserv = str(wi.name_servers) cur.execute("""INSERT INTO wrec (dname, wfull, dns) VALUES (%s, %s, %s)""", (domname, fullwhois, dnsserv)) – gejza May 14 '14 at 05:41