[Twisted-Python] problem with numpy and twisted xmlrpc

Daniel Sank sank.daniel at gmail.com
Wed Apr 30 12:13:18 MDT 2014


Nicola,

I don't know whether this makes sense in the context of xmlrpc, but perhaps
you can use numpy's tostring and fromstring functions. If you do this you
have to also send the datatype so that fromstring knows how to unpack
(that's the part where I'm not sure if this strategy is xmlrpc-ish).

-Daniel



On Wed, Apr 30, 2014 at 10:48 AM, Nicola Cesca <nicola.cesca at mail.com>wrote:

>  Hi all,
> I'm newbie. I got a lot of problem using xmlrpc and numpy
>
>  I'm using numpy to to some staff and then serve the results via a
> twisted/XMLRPC server. If the result is a numpy float 64, I get an
> exception cause probably twisted can't handle this type. Infact is I
> downgrade the result to float32 with x=float(x), everything is ok. This is
> not so good cause if I forget this workaroud somewhere, it's a pain. Have
> you any better solution?
>
> server:
>
> from twisted.web import xmlrpc, serverimport numpy as np
> class MioServer(xmlrpc.XMLRPC):
>     """
>     An example object to be published.
>     """
>
>     def xmlrpc_test_np(self):
>         return np.sqrt(2)
> if __name__ == '__main__':
>     from twisted.internet import reactor
>     r = MioServer()
>     reactor.listenTCP(7080, server.Site(r))
>     reactor.run()
>
> client:
>
> import xmlrpclib
> if __name__=='__main__':
>     x=xmlrpclib.ServerProxy('http://localhost:7080/')
>     print x.test_np()
>
> Exception:
>
> Traceback (most recent call last):
>   File "C:\Users\Stone\.eclipse\org.eclipse.platform_4.3.0_1709980481_win32_win32_x86\plugins\org.python.pydev_2.8.2.2013090511\pysrc\pydevd.py", line 1446, in <module>
>     debugger.run(setup['file'], None, None)
>   File "C:\Users\Stone\.eclipse\org.eclipse.platform_4.3.0_1709980481_win32_win32_x86\plugins\org.python.pydev_2.8.2.2013090511\pysrc\pydevd.py", line 1092, in run
>     pydev_imports.execfile(file, globals, locals) #execute the script
>   File "C:\Users\Stone\Documents\FastDose\src\Beagle\Prove e test\xmlrpc_client.py", line 28, in <module>
>     print x.test_np()
>   File "C:\Python27\lib\xmlrpclib.py", line 1224, in __call__
>     return self.__send(self.__name, args)
>   File "C:\Python27\lib\xmlrpclib.py", line 1578, in __request
>     verbose=self.__verbose
>   File "C:\Python27\lib\xmlrpclib.py", line 1264, in request
>     return self.single_request(host, handler, request_body, verbose)
>   File "C:\Python27\lib\xmlrpclib.py", line 1297, in single_request
>     return self.parse_response(response)
>   File "C:\Python27\lib\xmlrpclib.py", line 1473, in parse_response
>     return u.close()
>   File "C:\Python27\lib\xmlrpclib.py", line 793, in close
>     raise Fault(**self._stack[0])
> xmlrpclib.Fault: <Fault 8002: "Can't serialize output: cannot marshal <type 'numpy.float64'> objects">
>
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>


-- 
Daniel Sank
Department of Physics
Broida Hall
University of California
Santa Barbara, CA 93117
(805)893-3899
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20140430/7c833b88/attachment-0002.html>


More information about the Twisted-Python mailing list