def ensureKey(self, key, cur): try: cur.execute('INSERT INTO cvdata (key) values (%s)', (key, )) except psycopg2.IntegrityError: pass