By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 1,963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

XMLRPC binary file transfer

P: 15
Hi all,

I am trying to transfer files via xmlrpc. I am following the example found here:
under the binary objects section

Server Code
Expand|Select|Wrap|Line Numbers
  1. from SimpleXMLRPCServer import SimpleXMLRPCServer
  2. import xmlrpclib
  4. def python_logo():
  5.      handle = open("python_logo.jpg")
  6.      return xmlrpclib.Binary(
  7.      handle.close()
  9. server = SimpleXMLRPCServer(("localhost", 8000))
  10. print "Listening on port 8000..."
  11. server.register_function(python_logo, 'python_logo')
  13. server.serve_forever()[FONT=Arial][/FONT]
Client Code
Expand|Select|Wrap|Line Numbers
  1. import xmlrpclib
  3. proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
  4. handle = open("fetched_python_logo.jpg", "w")
  5. handle.write(proxy.python_logo().data)
  6. handle.close()
I can get txt files to transfer properly, but when I try to transfer other things like word documents and images it creates a file that are a fraction of the original size and nothing shows up when I open the file.

Am I missing something in my Python install that converts the binary objects properly?

Jan 14 '09 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 126
Try the following first, change :

Expand|Select|Wrap|Line Numbers
  1. handle = open("fetched_python_logo.jpg", "w")

Expand|Select|Wrap|Line Numbers
  1. handle = open("fetched_python_logo.jpg", "wb") 
(It could be something else aswell, but try this first)

Jan 15 '09 #2

P: 15
I added the "b" into the code but I am still having the same problem. I tried the code on linux and mac and it worked fine, but when I tried it on another windows machine(I am also running on windows) the same problem occurred. I guess python on windows does not play with this binary transfer nicely?
Jan 15 '09 #3

P: 7
On server side, you must do something like this:

Expand|Select|Wrap|Line Numbers
  1. handle = open("python_logo.jpg", 'rb')
Also, on client side, like @kudos said, you can write 'wb' instead 'w', but this is not mandatory...

May 20 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.