from sqlalchemy import create_engine
from sqlalchemy.exc import SQLAlchemyError
db_file='G:\\My drive\\testing\\my_db.db'
try:
file1='sqlite:///'+ db_file
my_conn = create_engine(file1)
# For MySQL use the below line and remove the above lines for SQLite file
#my_conn = create_engine("mysql+mysqldb://root:pw@localhost/my_tutorial")
r_set=my_conn.execute("SELECT * FROM student WHERE id =6")
data=r_set.fetchone()
except SQLAlchemyError as e:
error = str(e.__dict__['orig'])
print(error)
main.py