Search code examples
pythonexceptionsoapsoappy

How to know what exceptions a SOAPPy library is rising


this is more a question than a real problem.

I have some code using SOAPpy library in python :

from SOAPpy import SOAPProxy
...
try:
    connection = SOAPProxy(settings.SOAP_URL)
    session = connection.login(username, password)
    user = connection.getUserInfo(session.session_hash, session.user_id)
    groups = connection.getGroups(session.session_hash, settings.GROUP_ID)
    group = next(group for group in groups.item
        if group.name == settings.GROUP_NAME)
    next(member for member in group.member.item
        if member.user_name == user.username)
except:
    return None
...

My question is : Which exception can be raised by this part of code ?

Because a new contributor say that it's more Pythonic to write all exceptions which can be raised.

Best regards, Morony


Solution

  • The best way to have definite answer to this is read though the SOAPpy source code. However, this is cumbersome and waste of practical working time. Beside SOAPPy own exceptions, the underlying operating system may cause IOError and OSError exceptions and such.

    Because SOAPpy, like many other libraries, is not explicit what exceptions it can raise, it can be basically anything. So in this case, you cannot be Pythonic, because the library author has chosen to be "less Pythonic" or has not explicitly document how the library behaves.

    So the lesson to be learned here is that do not take anything granted, but apply your common sense.