This worked for me.
try: cnxn = pyodbc.connect(...) except pyodbc.Error as ex: sqlstate = ex.args if sqlstate == '28000': print("LDAP Connection failed: check password")
There are different SQLSTATES and you can have if-else statements to print out the cause.
try: cnxn = pyodbc.connect(...) except pyodbc.Error as ex: sqlstate = ex.args print(sqlstate)
will give you the second part of the error with description.
ex.args give you
 LDAP authentication failed for user 'user' (24) (SQLDriverConnect)
You can then use String manipulation techniques there to just print out what you want. Hope this helps.