mysqldb duplicate entry error handling

baur79 baur79 at gmail.com
Thu Feb 1 13:17:31 EST 2007


Hi guys


i try to run this code in loop and to pass even the entry is
duplicated

def email_insert_in_db(email):
  sql="INSERT INTO emails (email) values ('%s') "%(email)
  db=_mysql.connect(host = "localhost", user = db_user, passwd =
db_pass, db = db_name)

  try:
    db.query(sql)
  except IndentationError:
    print "duplicate"
    pass

also try to (raise, continue)
but can't continue in loop

error output is:
  File "inser_in_db.py", line 85, in email_insert_in_db
    db.query(sql)
IntegrityError: (1062, "Duplicate entry 'email at domain.com' for key 1")

thanks for your help

Baurzhan Zhakashev
Kazakhstan / Shymkent city




More information about the Python-list mailing list