473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

XMLRPC binary file transfer

Hi all,

I am trying to transfer files via xmlrpc. I am following the example found here:
http://docs.python.org/library/xmlrpclib.html
under the binary objects section

Server Code
Expand|Select|Wrap|Line Numbers
  1. from SimpleXMLRPCServer import SimpleXMLRPCServer
  2. import xmlrpclib
  3.  
  4. def python_logo():
  5.      handle = open("python_logo.jpg")
  6.      return xmlrpclib.Binary(handle.read())
  7.      handle.close()
  8.  
  9. server = SimpleXMLRPCServer(("localhost", 8000))
  10. print "Listening on port 8000..."
  11. server.register_function(python_logo, 'python_logo')
  12.  
  13. server.serve_forever()[FONT=Arial][/FONT]
Client Code
Expand|Select|Wrap|Line Numbers
  1. import xmlrpclib
  2.  
  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?

Thanks.
Jan 14 '09 #1
3 10851
kudos
127 Expert 100+
Try the following first, change :

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

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

-kudos
Jan 15 '09 #2
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
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...

Regards,
Stole
May 20 '09 #4

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

Similar topics

0
by: glin | last post by:
Hi I am trying to integrate the xmlrpc server into a class, does anyone know how to get it working? test.html: <html> <head> <title>XMLRPC Test</title> <script src="jsolait/init.js"></script>...
1
by: Joxean Koret | last post by:
Hi to all! I'm having troubles to make my XMLRPC application working with non ASCII characters. Example: 1.- In one terminal run the following script: -----------XMLRPC...
4
by: dcrespo | last post by:
....If the answer is Yes, can you give me an example either in the server side and the client side? I googled a lot, but I can't find nothing regarding this. A lot of thanks. Daniel
1
by: emielvl | last post by:
Hello, I'm developing a client/server architecture based on the XML-RPC implementation in php4. All works pretty well, except that in the response from the server there is no "Content-Length" in...
13
by: greg | last post by:
Hello, I'm searching to know if a local file is ascii or binary. I couldn't find it in the manual, is there a way to know that ? thanks, -- greg
7
by: Laszlo Nagy | last post by:
Hello, I'm trying to create a simple XMLRPC server and a client. It is a small application, but the connection needs to be secure. I would like the client to be as thin as possible. Ideally, the...
8
by: Daniel Crespo | last post by:
Hello everybody, I'm trying to implement a secure xmlrpc server with basis on http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496786 recipe. The thing that I'm concerned about is how can...
0
by: Benjamin Grieshaber | last post by:
Hi, I´m on SuSE 9.3 with xmlrpc-c and xmlrpc-c-devel installed (ver. 0.9.10) I tried to compile php with xmlrpc support and got the following errors: ...
4
by: care02 | last post by:
I have implemented a simple Python XMLRPC server and need to call it from a C/C++ client. What is the simplest way to do this? I need to pass numerical arrays from C/C++ to Python. Yours, Carl
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.