mxODBC error trapping

Paul Boddie paulb at
Wed Apr 26 06:31:17 EDT 2000

Joshua Macy wrote:
> "Daley, MarkX" wrote:
> >
> > Traceback (innermost last):
> >   File "<pyshell#1>", line 1, in ?
> >     collect.collect()
> >   File "C:\PROGRA~1\Python\", line 50, in collect
> >     except dbi.OperationalError:
> > AttributeError: OperationalError
> >
> > Here is the printout of the dbi module:
> >
> > ['DATE', 'NUMBER', 'RAW', 'ROWID', 'STRING', 'TYPES', '__doc__', '__file__',
> > '__name__', 'dataError', 'dbDate', 'dbRaw', 'dbiDate', 'dbiRaw',
> > 'integrityError', 'internalError', 'noError', 'opError', 'progError']
>   According to the dbi module dictionary (which you've printed), it
> looks like it should be opError, not OperationalError.  Or you could
> just use an unqualified except, and be sure of catching any error that
> the dbi can raise.

You should be looking in the module where the 'connect' function was defined.
So, if you used 'ODBC.iODBC.connect' to connect to the database, you will find
that 'OperationalError' is defined in 'ODBC.iODBC' too:

>>> dir(ODBC.iODBC)
'DataError', 'DatabaseError', 'DriverConnect', 'Error', 'FLOAT', 'INTEGER',
'IntegrityError', 'InterfaceError', 'InternalError', 'LONGVARBINARY',
'LONGVARCHAR', 'NUMERIC', 'NotSupportedError', 'OperationalError',
'VARBINARY', 'VARCHAR', 'Warning', '__builtins__', '__doc__', '__file__',
'__name__', '__path__', '__version__', 'apilevel', 'connect', 'error',
'errorclass', 'mxODBC', 'mxODBCType', 'mxODBCursorType', 'paramstyle',
'sqltype', 'threadlevel']

It would be "expected" that errors and exceptions were defined in the same
module as the classes and functions, but I suppose the structure of mxODBC makes
this assumption a little uncertain. Still, 'dir' used liberally often tells you
what you need to know.


More information about the Python-list mailing list