1import os
2import snowflake.connector
3from snowflake.connector.errors import DatabaseError, ProgrammingError
4
5snowflake_account = os.environ['SNOWFLAKE_ACCOUNT']
6
7if __name__ == '__main__':
8 try:
9 con = snowflake.connector.connect(
10 user='bad username', # <-------- Bad user
11 password='bad password', # <-------- Bad pass
12 account=snowflake_account # <-------- This is correct
13 )
14 except DatabaseError as db_ex:
15 if db_ex.errno == 250001:
16 print(f"Invalid username/password, please re-enter username and password...")
17 # code for user to re-enter username & pass
18 else:
19 raise
20 except Exception as ex:
21 # Log this
22 print(f"Some error you don't know how to handle {ex}")
23 raise
24 else:
25 try:
26 results = con.cursor().execute("select * from db.schema.table").fetchall()
27 print(results)
28 except ProgrammingError as db_ex:
29 print(f"Programming error: {db_ex}")
30 raise
31 finally:
32 con.close()
33
34