[Twisted-Python] problem with numpy and twisted xmlrpc

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">|

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@mail.com>wrote:
-- Daniel Sank Department of Physics Broida Hall University of California Santa Barbara, CA 93117 (805)893-3899

I don't know whether this makes sense in the context of xmlrpc, but
Nicola, Since you responded to my last message directly rather than to the list, I am putting our conversation here for clarity. Please respond to the list rather than to single users. perhaps
you can use numpy's tostring and fromstring functions.
I get an exception cause probably twisted can't handle this type.
This is not a twisted problem. If you read the error message you put in your original email you'll see near the end that it says 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"> So you can see that the error is in xmlrpclib, and that the problem is that marshal does not support numpy arrays.
I dont know what is from/tostring.
Ok, are you only interested in solutions that use functions you already know about? I was going to explain how to deal with this, but since I see you posted an identical question on stackoverflow I guess I'll go answer it there (since this isn't a twisted problem after all). Daniel On Wed, Apr 30, 2014 at 11:13 AM, Daniel Sank <sank.daniel@gmail.com> wrote:
-- Daniel Sank Department of Physics Broida Hall University of California Santa Barbara, CA 93117 (805)893-3899

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@mail.com>wrote:
-- Daniel Sank Department of Physics Broida Hall University of California Santa Barbara, CA 93117 (805)893-3899

I don't know whether this makes sense in the context of xmlrpc, but
Nicola, Since you responded to my last message directly rather than to the list, I am putting our conversation here for clarity. Please respond to the list rather than to single users. perhaps
you can use numpy's tostring and fromstring functions.
I get an exception cause probably twisted can't handle this type.
This is not a twisted problem. If you read the error message you put in your original email you'll see near the end that it says 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"> So you can see that the error is in xmlrpclib, and that the problem is that marshal does not support numpy arrays.
I dont know what is from/tostring.
Ok, are you only interested in solutions that use functions you already know about? I was going to explain how to deal with this, but since I see you posted an identical question on stackoverflow I guess I'll go answer it there (since this isn't a twisted problem after all). Daniel On Wed, Apr 30, 2014 at 11:13 AM, Daniel Sank <sank.daniel@gmail.com> wrote:
-- Daniel Sank Department of Physics Broida Hall University of California Santa Barbara, CA 93117 (805)893-3899
participants (2)
-
Daniel Sank
-
Nicola Cesca