[Fedora-suds-list] Exceptions

Joshua J. Kugler joshua at eeinternet.com
Mon Jun 14 20:28:09 UTC 2010


On Monday 14 June 2010, Edwin Vane elucidated thus:
> I apologize if these questions have been asked before. I wasn't able
> to find a mailing list archive search.
>
> Is there an easy way to determine the SOAP exception object that was
> raised from a suds.WebFault? It looks to me that using __str__ and
> trying to parse the string is the only way to get the object. Is
> there a better way?

suds.WebFault exceptions are objects, so you can do some querying like:

except WebFault, ex:
    if ('LoginFault' in ex.fault.detail
        and ex.fault.detail.LoginFault.exceptionCode 
== 'INVALID_LOGIN'):
        log.critical('Invalid credentials supplied for Salesforce')

Another example:

except WebFault, ex:
    if ('ApiFault' in ex.fault.detail
        and ex.fault.detail.ApiFault.message.startswith('Login 
failed')):
       log.critical('Invalid credentials supplied for Yahoo')

What, exactly, you query for can depend on the service and the call 
you're performing.

> When exceptions are thrown I get this error printed to stdout/stderr:
>
> No handlers could be found for logger "suds.client"
>
> Is there a way to turn off this message without having to use the
> logging module? I would think if I didn't request logging that the
> module shouldn't complain that I'm not using it right?

If you want to ignore messages, you can just do something like:

logging.getLogger('suds.client').setLevel(logging.CRITICAL)

or make another similar call which will mute most or all messages.

j

-- 
Joshua Kugler
Part-Time System Admin/Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/  ID 0x73B13B6A


More information about the suds mailing list