title: Python - SqlAlchemy - how to insert gracefully, by avoiding duplicates?
body: <p>I've tried this, but without luck:</p>
  
  <pre><code>def sqlTryInsert(result_obj):
   try:
    session.add(result_obj)
    session.flush()
    session.commit() 
   except (exc.SQLAlchemyError, exc.DBAPIError) as e:
    code, msg = e.orig
    if code == 1062:
      # send warning
      pass
  </code></pre>
  
  <p>I still get this error:</p>
  
  <pre><code>sqlalchemy.exc.IntegrityError: (_mysql_exceptions.IntegrityError) (1062, 
  "Duplicate entry '...' for key 'hash'") 
  [SQL: 'INSERT INTO results (...) VALUES (...)'] [parameters: (...)] 
  (Background on this error at: http://sqlalche.me/e/gkpj)
  </code></pre>