Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

snowflake python connector error handling

import os
import snowflake.connector
from snowflake.connector.errors import DatabaseError, ProgrammingError

snowflake_account = os.environ['SNOWFLAKE_ACCOUNT']

if __name__ == '__main__':
    try:
        con = snowflake.connector.connect(
            user='bad username',       # <-------- Bad user
            password='bad password',   # <-------- Bad pass
            account=snowflake_account  # <-------- This is correct
        )
    except DatabaseError as db_ex:
        if db_ex.errno == 250001:
            print(f"Invalid username/password, please re-enter username and password...")
            # code for user to re-enter username & pass
        else:
            raise
    except Exception as ex:
        # Log this
        print(f"Some error you don't know how to handle {ex}")
        raise
    else:
        try:
            results = con.cursor().execute("select * from db.schema.table").fetchall()
            print(results)
        except ProgrammingError as db_ex:
            print(f"Programming error: {db_ex}")
            raise
        finally:
            con.close()

Comment

PREVIOUS NEXT
Code Example
Python :: python pandas csv to xlsx semicolon 
Python :: how to write words on any other apps in python 
Python :: use sqlalchemy to create sqlite3 database 
Python :: python show image cv2 
Python :: find geomean of a df 
Python :: what is ycor in python turle 
Python :: serving static audio files with flask in react 
Python :: olst = [] a = int(input()) b = int(input()) for ele in range(a,b+1): if ele%2 != 0: olst.append(ele) print(olst[::-1]) 
Python :: fruit shop using list in python 
Python :: Goal Perser 
Python :: worksheet merge&center cells python 
Python :: is prime python 
Python :: plotly express lineplot 
Python :: Python Time object to represent time 
Python :: dashes seaborn 
Python :: sort dictionary python 
Python :: reverse keys and values in dictionary with zip python 
Python :: how to remove trackback on python when ctrl c 
Python :: minimum from list of tuples 
Python :: python diffie hellman 
Python :: how to ascess GPS in python 
Python :: change pandas column value based on condition 
Python :: how to put more than one file type in pysimplegui 
Python :: flask give port number 
Python :: default style matplotlib python 
Python :: add day in date python 
Python :: how to print a line letter by letter in python 
Python :: how to pronounce aesthetic 
Python :: datetime to string python 
Python :: python one line return 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =