mxODBC error trapping

Fredrik Lundh effbot at telia.com
Tue Apr 25 14:12:39 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





More information about the Python-list mailing list