mysqldb duplicate entry error handling
Chris Mellon
arkanes at gmail.com
Thu Feb 1 13:33:59 EST 2007
On 1 Feb 2007 10:17:31 -0800, baur79 <baur79 at gmail.com> wrote:
> 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
>
> --
If you want to catch IntegrityError, why are you actually catching
IndentationError?
More information about the Python-list
mailing list