I would like to write and exception for the database does not exist, so I can create it and return back to the top (retry the connection).
How do you get specific when writing exceptions?
Can you have two or more exceptions?
try:
    db_con = psycopg2.connect(host='HOSTNAME', database='MYDB', user='USERNAME', password='PASSWORD')
    cur = db_con.cursor()
    cur.execute('SELECT version()')
    ver = cur.fetchone()
    print ver
except psycopg2.DatabaseError, e:
    print 'Error %s' % e
    sys.exit(1)
finally:
    if db_con:
        db_con.close()
 
     
    