Using twisted to process files

VeNeX

New Member
I'm trying to set up a twisted xmlrpc server, which will accept files from a client, process them, and return a file and result dictionary back.I've used python before, but never the twisted libraries. For my purposes security is a non issue, and the ssh protocol seems like overkill. It also has problems on the windows server, since \[code\]termios\[/code\] is not available. So all of my research points to xmlrpc being the best way to accomplish this. However, there are two methods of file transfer available. Using the \[code\]xml binary data\[/code\] method, or the \[code\]http request\[/code\] method.Files can be up to a few hundred megs either way, so which method should I use? Sample code is appreciated, since I could find no documentation for file transfers over xml with twisted.Update:So it seems that serializing the file with \[code\]xmlrpclib.Binary\[/code\] does not work for large files, or I'm using it wrong. Test code below:\[code\]from twisted.web import xmlrpc, serverclass Example(xmlrpc.XMLRPC): """ An example object to be published. """ def xmlrpc_echo(self, x): """ Return all passed args. """ return x def xmlrpc_add(self, a, b): """ Return sum of arguments. """ return a + b def xmlrpc_fault(self): """ Raise a Fault indicating that the procedure should not be used. """ raise xmlrpc.Fault(123, "The fault procedure is faulty.") def xmlrpc_write(self, f, location): with open(location, 'wb') as fd: fd.write(f.data)if __name__ == '__main__': from twisted.internet import reactor r = Example(allowNone=True) reactor.listenTCP(7080, server.Site(r)) reactor.run()\[/code\]And the client code:\[code\]import xmlrpclibs = xmlrpclib.Server('http://localhost:7080/')with open('test.pdf', 'rb') as fd: f = xmlrpclib.Binary(fd.read())s.write(f, 'output.pdf')\[/code\]I get \[code\]xmlrpclib.Fault: <Fault 8002: "Can't deserialize input: ">\[/code\] when I test this. Is it because the file is a pdf?
 
Back
Top