Simple CGI-XMLRPC failure

Jeff McNeil jeff at jmcneil.net
Mon Jan 12 21:02:04 EST 2009


On Jan 12, 12:40 pm, "Mike MacHenry" <dski... at ccs.neu.edu> wrote:
> I am having a difficult time understanding why my very simple
> CGI-XMLRPC test isn't working. I created a server to export two
> functions, the built-in function "pow" and my own identity function
> "i". I run a script to call both of them and the "pow" work fine but
> the "i" gives me an error that says my XMLRPC server doesn't support
> than name. Here is the code for both files and the output:
>
> #!/usr/bin/env python
> #This file is /usr/lib/cgi-bin/roundwarerpc.py
> from SimpleXMLRPCServer import CGIXMLRPCRequestHandler
> def i(x):
>         return x
> server = CGIXMLRPCRequestHandler()
> server.register_function(pow)
> server.register_function(i)
> server.handle_request()
>
> #!/usr/bin/env python
> #This file is ~/test.py
> import xmlrpclib
> server = xmlrpclib.ServerProxy("http://localhost/cgi-bin/roundwarerpc.py")
> print server.pow(2,3)
> print server.i(10)
>
> #This is the STDOUT and STDERR when running ~/test.py
> dskippy at dskippy-laptop:$ python test.py 8
> Traceback (most recent call last):
>   File "test.py", line 4, in <module>
>     print server.test(10)
>   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.Exception\'>:method "i"
> is not supported'>
>
> Does anyone know what might be wrong with this?
>
> Thanks for the help,
> -mike
>
> p.s.
> Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
> [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
> Server version Apache/2.2.8 (Ubuntu)
> Server built: Jun 25 2008 13:54:13

I copied your code verbatim and I don't have any issues with it at
all. Same version of Python, same version of Apache.

In SimpleXMLRPCServer.py, register_function adds directly to a
self.funcs dictionary, so an instance variable of the same name
shouldn't hurt anything.  That exception is only raised when a
self.funcs lookup raises a KeyError unless you're registering an
instance.




More information about the Python-list mailing list