Identifying sqlalchemy.exc.OperationalError
After some more research, I found the mysql error code to be in err.orig.args[0]
. So the Answer is:
try:
engine.scalar(select([1]))
except sqlalchemy.exc.OperationalError as err:
if err.orig.args[0]==1045:
print("Access Denied")
elif err.orig.args[0]==2003:
print("Connection Refused")
else:
raise