Error Handling in Python with SUDS
Asked Answered
B

4

14

I have been trying to control a camera through a wsdl file using SUDS. I have got the code working but I want to place error handling into the script. I have tried different exceptions but am unable to get the script working. When I enter an invalid coordinate I get an error. The code I am using is below followed by the error I am recieving.

#!/home/build/Python-2.6.4/python

import suds
from suds.client import Client

####################################################################
#
#   Python SUDS Script that controls movement of Camera
#
####################################################################
#
#                    Absolute Move Function
#
####################################################################

def absoluteMove():

    # connects to WSDL file and stores location in variable 'client'
    client = Client('http://file.wsdl')

    # Create 'token' object to pass as an argument using the 'factory' namespace
    token = client.factory.create('ns4:ReferenceToken')
    print token

    # Create 'dest' object to pass as an argument and values passed to this object
    dest = client.factory.create('ns4:PTZVector')
    dest.PanTilt._x=400
    dest.PanTilt._y=0
    dest.Zoom._x=1
    print dest

    # Create 'speed' object to pass as an argument and values passed to this object
    speed = client.factory.create('ns4:PTZSpeed')
    speed.PanTilt._x=0
    speed.PanTilt._y=0
    speed.Zoom._x=1
    print speed

    # 'AbsoluteMove' method invoked passing in the new values entered in the above objects

    try:
        result = client.service.AbsoluteMove(token, dest, speed)
    except RuntimeError as detail:
        print 'Handling run-time error:', detail

    print "absoluteMove result ", result

result = absoluteMove() 

The error is below:

No handlers could be found for logger "suds.client"
Traceback (most recent call last):
  File "ptztest.py", line 48, in <module>
    if __name__ == '__main__': result = absoluteMove()    
  File "ptztest.py", line 42, in absoluteMove
    result = client.service.AbsoluteMove(token, dest, speed)
  File "build/bdist.linux-i686/egg/suds/client.py", line 537, in __call__
  File "build/bdist.linux-i686/egg/suds/client.py", line 597, in invoke
  File "build/bdist.linux-i686/egg/suds/client.py", line 632, in send
  File "build/bdist.linux-i686/egg/suds/client.py", line 683, in failed
  File "build/bdist.linux-i686/egg/suds/bindings/binding.py", line 235, in get_fault
suds.WebFault: Server raised fault: 'Error setting requested pan'

I am not sure which exception I should be using here. Does anyone know how to catch this error. The x coordinate with the value 400 is in degree's that is why the error happens.

Thanks

Okay I have found the solution. In SUDS if you enter:

faults=False

into the client definition, this catches faults and gives the reason why the fault happened. The line should read:

client = Client('http://file.wsdl', faults=False)

The post that I have marked as the correct answer also is able to catch that a problem has happened.

Thanks all

Baecher answered 18/1, 2010 at 9:56 Comment(0)
G
12

If you want to catch that exception you should put

try:
    result = client.service.AbsoluteMove(token, dest, speed)
except suds.WebFault as detail:
    ...
Geriatrician answered 18/1, 2010 at 10:6 Comment(1)
I have put faults=False and tried to catch suds.WebFault, but still getting that error "No handlers could be found for logger "suds.client"Meseems
B
15

If you handled all exceptions and errors in your code and your code is working fine but still you are getting below message with your correct output.

Msg : "No handlers could be found for logger suds.client "

Then a simple solution is to add this line

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

in yourclient.py file just after all import statement.

Blanc answered 10/10, 2011 at 12:2 Comment(2)
and don't forget: import loggingXenon
That removes the client debugging, it doesn't fix the issue. To get the suds.client logging facility running, you must first do a logging.basicConfig call. eg: logging.basicConfig(level=logging.INFO)Bilski
G
12

If you want to catch that exception you should put

try:
    result = client.service.AbsoluteMove(token, dest, speed)
except suds.WebFault as detail:
    ...
Geriatrician answered 18/1, 2010 at 10:6 Comment(1)
I have put faults=False and tried to catch suds.WebFault, but still getting that error "No handlers could be found for logger "suds.client"Meseems
R
1

You need to catch suds.WebFault by the looks of that traceback. The error itself seems legitimate, IE, your requests are being executed correctly, but perhaps your parameters are wrong in the given context.

Rope answered 18/1, 2010 at 10:2 Comment(0)
C
0

I believe you refer to a harmless diagnostic message in your comment. I could suppress messages from suds calling logging.error() by assigning logging.INFO to basicConfig and logging.CRITICAL to suds.client.

https://fedorahosted.org/suds/wiki/Documentation

Commandment answered 9/8, 2011 at 19:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.