[spyne] Help with Spyne HttpRpc

Rodolfo Narciso Duldulao Jr. rduldulao at chikka.com
Tue May 13 04:50:42 UTC 2014


Hello all,
Spyne newbie here.  I am trying to find a way to limit HttpRpc requests to use POST request method only.  We have a web service that according to a spec, should be accessible via HTTP POST only.  I have made a decorator to check for the REQUEST_METHOD value like so:
class OurWebService(ServiceBase):    @rpc(Unicode, _returns=Iterable(String))    @require_methods(['POST'])    def say_hello(ctx, name):         yield "Hello %s." % name      #from the example



Here's the code for the require_methods decorator:
class require_methods(object):    def __init__(self, methods):        assert isinstance(methods, list), "Methods should be in list form."        self.methods = methods
    def __call__(self, f):
        def wrapped_f(*args, **kwargs):            assert args[0], "No context param"            assert getattr(args[0], 'in_document'), "No context info"            if args[0].in_document.get('REQUEST_METHOD') not in self.methods:                raise InvalidMethodError()            pprint(args)            f(*args, **kwargs)
        wrapped_f.__doc__ = f.__doc__        return wrapped

When I access the web service via GET, I get an Error 500 and I see the InvalidMethodError stack trace logged on my console - which is to be expected.When I use POST (using a REST Console), it says these on the debug output:
DEBUG:spyne.protocol.http: body   : {'name': ['Dave']}DEBUG:spyne.protocol.dictdoc:discarding field 'name'... (Stack trace here with lines coming from the decorator code)
TypeError: say_hello() takes exactly 2 arguments (1 given)
It seems to me, the rpc decorator didn't recognize the name parameter now that the service method is wrapped by another decorator.  Am I doing the correct approach?  Any advice is appreciated. 
Thanks,

Rodolfo N. Duldulao, Jr.Chikka Philippines, Inc. Penthouse,23 ADB Avenue, Ortigas Center,Pasig City 1605 Metro Manila, Philippines 
Email: rduldulao at chikka.com Mobile: 09209515026 Tel: 029889629
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spyne.io/archives/people/attachments/20140513/14452899/attachment.html>


More information about the people mailing list