mxODBC error trapping

Daley, MarkX markx.daley at intel.com
Tue Apr 25 17:02:46 EDT 2000


>>Daley, MarkX <markx.daley at intel.com> wrote:
>> I am accessing databases using the notes by John Dell'Aquila for ODBC
using
>> Python Database API.  It works fine, but now I am trying to set up error
>> trapping in the event that a connection fails to be made.  Here is the
basic
>> code structure:
>>
>> def collect():
>>     "Routine to query all servers for all names for time period defined
>>     in timer."
>>    # Define some variables
>>    for index in servername:
>>        try:
>>            # Big routine to collect data and write to file
>>        except dbi.operation-error:
>>            servername.append(index)

>"operation-error" is not a valid name (it's interpreted
>as "operation" minus "error").

>> I guess I don't know enough about exceptions to trap them properly.  Any
>> hints?

>according to the DB specification [1], OperationalError is the
>correct name.  you still have to qualify it with the module name,
>though:

>    try:
>        ...
>    except dbi.OperationalError:
>        ...

>if that doesn't work, try printing the contents of the "dbi" module:

>print dir(dbi)

></F>

>1) http://www.python.org/topics/database/DatabaseAPI-2.0.html


When I use dbi.OperationalError, I get this result:

Traceback (innermost last):
  File "<pyshell#1>", line 1, in ?
    collect.collect()
  File "C:\PROGRA~1\Python\collect.py", 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']

I am way out of my depth here.  Any and all help is appreciated.

- Mark





More information about the Python-list mailing list