[Twisted-Python] problem with numpy and twisted xmlrpc

Nicola Cesca nicola.cesca at mail.com
Wed Apr 30 11:48:27 MDT 2014


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.webimport  xmlrpc,  server
import  numpyas  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.internetimport  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",  line1446,  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",  line1092,  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",  line28,  in  <module>
     print  x.test_np()
   File  "C:\Python27\lib\xmlrpclib.py",  line1224,  in  __call__
     return  self.__send(self.__name,  args)
   File  "C:\Python27\lib\xmlrpclib.py",  line1578,  in  __request
     verbose=self.__verbose
   File  "C:\Python27\lib\xmlrpclib.py",  line1264,  in  request
     return  self.single_request(host,  handler,  request_body,  verbose)
   File  "C:\Python27\lib\xmlrpclib.py",  line1297,  in  single_request
     return  self.parse_response(response)
   File  "C:\Python27\lib\xmlrpclib.py",  line1473,  in  parse_response
     return  u.close()
   File  "C:\Python27\lib\xmlrpclib.py",  line793,  in  close
     raise  Fault(**self._stack[0])
xmlrpclib.Fault:  <Fault  8002:  "Can't serialize output: cannot marshal <type 'numpy.float64'> objects">|


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20140430/78a51e82/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nicola_cesca.vcf
Type: text/x-vcard
Size: 174 bytes
Desc: not available
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20140430/78a51e82/attachment.vcf>


More information about the Twisted-Python mailing list