Export to GitHub

django-xmlrpc - issue #3

how to use permission_required() decorator?


Posted on Jul 26, 2008 by Quick Wombat

Hi, I need to get private some xmlrpc methods but I don't know how to use the permession_required decorator, with this code:

@xmlrpc_func(returns='array') @permission_required() def getProdotti(): """Prende tutti i prodotti dal database""" prodotti = Prodotto.objects.all() p = serializers.serialize("python", prodotti) return p

I get this error: Traceback (most recent call last): File "gestionale.py", line 5, in <module> prodotti = s.getProdotti() File "/usr/lib/python2.5/xmlrpclib.py", line 1147, in call return self.__send(self.__name, args) File "/usr/lib/python2.5/xmlrpclib.py", line 1437, in __request verbose=self.__verbose File "/usr/lib/python2.5/xmlrpclib.py", line 1201, in request return self._parse_response(h.getfile(), sock) File "/usr/lib/python2.5/xmlrpclib.py", line 1340, in _parse_response return u.close() File "/usr/lib/python2.5/xmlrpclib.py", line 787, in close raise Fault(**self._stack[0]) xmlrpclib.Fault: <Fault 1: "<type 'exceptions.TypeError'>:__authenticated_call() takes at least 2 arguments (0 given)">

Comment #1

Posted on Jun 5, 2009 by Helpful Bear

maybe is to late, but your are right. If you don't read carefully the decorator code, you cannot know how to use it.

To use it, change your code like this:

def getProdotti(self): """Prende tutti i prodotti dal database""" prodotti = Prodotto.objects.all() p = serializers.serialize("python", prodotti) return p

...

Note the self variable on the parameters of the function

Status: New

Labels:
Type-Defect Priority-Medium