I'm currently implementing an XML-RPC service in Python where binary
data is sent to the server via URLs. However, some clients that need
to access the server may not have access to a web server, and I need to
find a solution. I came up with the idea of embedding a simple HTTP
server in the XML-RPC clients so that files can be sent in the
following way:
1. Start an HTTP server on the client using e.g SImpleHTTPServe r on a
user allowed port
2. Call XML-RPC server with the URL to the file on the client to
upload
3. Get XML-RPC server response, then shut down HTTP server on client
Does this sound reasonable? I know that XML-RPC can send binary data,
but I presume that the URL method would be faster because the XML
parser could skip reading the binary file (is it base64 encoded as a
string like in SOAP?).
Anyway, I'm unsure of how to implement this in Python. In particular,
how do I shut down a web server once I've started it with
server_forever( )? Should I run the server in a separate thread or run
it asynchronously? Since I'm only uploading one file I don't really
need to handle multiple clients; I just need to be able to shut the
server down once remote call has finished.
Any help would be appreciated since I'm new to network programming.
Jeremy 9 2982
jbrewer wrote:
I'm currently implementing an XML-RPC service in Python where binary
data is sent to the server via URLs. However, some clients that need
to access the server may not have access to a web server, and I need to
find a solution. I came up with the idea of embedding a simple HTTP
server in the XML-RPC clients so that files can be sent in the
following way:
1. Start an HTTP server on the client using e.g SImpleHTTPServe r on a
user allowed port
2. Call XML-RPC server with the URL to the file on the client to
upload
3. Get XML-RPC server response, then shut down HTTP server on client
Does this sound reasonable?
why not just use an ordinary HTTP POST request ?
</F>
Fredrik Lundh wrote:
>why not just use an ordinary HTTP POST request ?
Sorry for such a simple question, but how would I do this? XML-RPC
runs on top of HTTP, so can I do a POST without running a separate HTTP
server?
Jeremy
jbrewer wrote:
Sorry for such a simple question, but how would I do this? XML-RPC
runs on top of HTTP, so can I do a POST without running a separate HTTP
server?
the XML-RPC protocol uses HTTP POST, so if you can handle XML-RPC, you
should be able to handle any POST request. what server are you using ?
</F>
>What server are you using?
Just SimpleXMLRPCSer ver from the standard library.
jbrewer wrote:
Just SimpleXMLRPCSer ver from the standard library.
which means that you should be able to do something like
from SimpleXMLRPCSer ver import SimpleXMLRPCSer ver,\
SimpleXMLRPCReq uestHandler
class MyRequestHandle r(SimpleXMLRPCR equestHandler):
def do_POST(self):
if self.path != "/data":
return SimpleXMLRPCReq uestHandler.do_ POST(self)
# handle POST to /data
bytes = int(self.header s["content-length"])
# copy 'bytes' bytes from self.rfile (in some way)
data = self.rfile.read (bytes)
# ... deal with data here ...
response = "OK"
self.send_respo nse(200)
self.send_heade r("Content-type", "text/plain")
self.send_heade r("Content-length", str(len(respons e)))
self.end_header s()
self.wfile.writ e(response)
self.wfile.flus h()
self.connection .shutdown(1)
SimpleXMLRPCSer ver((host, port), requestHandler= MyRequestHandle r)
</F>
Fredrik Lundh wrote:
the XML-RPC protocol uses HTTP POST, so if you can handle XML-RPC, you
should be able to handle any POST request. what server are you using ?
I need some clarification of your suggestion. Instead of sending URLs,
I could read the file as a string, create a Binary object, and send
that via XML-RPC. The parameters will be sent to the server via HTTP
POST. However, the file will be encoded as a base64 string and
included in the body of the XML-RPC message, so it will have to be
parsed by the server. In my experience with SOAP, I have found this to
be extremely inefficient.
Are you suggesting sending the file separately thought a 2nd HTTP POST
with no XML-RPC message body? I guess the POST request would look
something like:
POST /path/file HTTP/1.0
From: ...
User-Agent: ...
Content-Type: /application/binary
Content-Length: <file size>
<file contents>
I'm not sure how to add a 2nd request like this. How would I alter a
simple call like that below to inlcude the 2nd post? Do I need to use
httplib and the request() method of HTTPConnection? Or can I make
POSTs through a ServerProxy object?
import xmlrpclib
server = xmlrpclib.Serve rProxy("http://myserver")
result = server.my_funct ion(file, params)
Jeremy
OK, I posted my previous message before I saw your reply on how to
handle the server side. On the client side, should I use
httplib.HTTPCon nection.request () to upload the data or can I do this
through xmlrpc.ServerPr oxy objects?
Jeremy
I have recently implemented a system where clients connect to an RPC
server (RPyC in my case), run a webserver on the RPC server, and close
the webserver when they're done with it.
To do this I wrote a ServerThread class which wraps a SimpleHTTPServe r,
runs as a thread, and can be signalled to stop. The ServerThread class
doesn't use the server_forever( ) method (which is just "while 1:
self.handle_req uest()"), instead it has a while loop which checks a
flag which is signalled from outside.
We need to set a timeout for the handle_request( ) call. The first thing
I tried was to use Python's socket object's new 'set_timeout' method,
but I found it caused mysterious errors to occur on my WindowsXP
machine :( Instead I call select() on the server's listening socket to
check for incoming requests, and only then call handle_request( ).
select()'s timeout works :)
# This is the heart of the code - the request handling loop:
while not self.close_flag .isSet():
# Use select() to check if there is an incoming request
r,w,e = select.select([self.server.soc ket], [], [],
self.timeout)
if r:
self.server.han dle_request()
# The stop method should be called to stop the request handling loop
def stop(self, wait=False):
self.close_flag .set()
if wait:
while self.isAlive(): # isAlive() is inherited from
threading.Threa d
time.sleep(self .timeout/10.0)
(in my case, self.stop_flag is a threading.Event object)
Good luck!
jbrewer wrote:
I'm currently implementing an XML-RPC service in Python where binary
data is sent to the server via URLs. However, some clients that need
to access the server may not have access to a web server, and I need to
find a solution. I came up with the idea of embedding a simple HTTP
server in the XML-RPC clients so that files can be sent in the
following way:
1. Start an HTTP server on the client using e.g SImpleHTTPServe r on a
user allowed port
2. Call XML-RPC server with the URL to the file on the client to
upload
3. Get XML-RPC server response, then shut down HTTP server on client
Does this sound reasonable? I know that XML-RPC can send binary data,
but I presume that the URL method would be faster because the XML
parser could skip reading the binary file (is it base64 encoded as a
string like in SOAP?).
Anyway, I'm unsure of how to implement this in Python. In particular,
how do I shut down a web server once I've started it with
server_forever( )? Should I run the server in a separate thread or run
it asynchronously? Since I'm only uploading one file I don't really
need to handle multiple clients; I just need to be able to shut the
server down once remote call has finished.
Any help would be appreciated since I'm new to network programming.
Jeremy
Thank you very much, Fredrik. Your code and suggestion worked
perfectly. I haven't benchmarked the plain HTTP post vs Binary
wrapper, but strangely even using the naive Binary wrapper in Python
sends files much faster than how Java + Axis wraps byte arrays in SOAP
messages.
Jeremy This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Robert J Egan |
last post by:
Hi i'm trying to search a remote website page. The form returns xml
information, though the page extension is missing. I retrieve the
information and write it to the screen. So far so good - However i cannot
format this information in anyway. A copy of the returned information saved
to my server results in the xml data being formatted and displayed as
intended! Can anyone explain to me why one would work but not the other.
Regards
...
|
by: MarionEll |
last post by:
Premier XML Industry Event Slated for Dec. 7-12 in Philadelphia; Presenters
Include Adobe, BEA, Microsoft, IBM, Sun, Hewlett-Packard, Oracle
Alexandria, Va. Sept. 30, 2003 - IDEAlliance, a leading trade association
dedicated to fostering XML and other information technology standards, today
announced the full program for XML Conference and Exposition 2003, being held
Dec. 7-12, at the Pennsylvania Convention Center in Philadelphia,...
|
by: yzzzzz |
last post by:
Hi,
In which cases is the <?xml version="1.0" encoding="UTF-8"?> processing
instruction required at the beginning of an XML document, for the
document to be valid?
e.g. does it depend on the encoding used in the document, of the version
of XML being used...
Thanks.
|
by: MarionEll |
last post by:
XML 2003 Exposition Draws Leading XML Vendors
Trade Show, Presentations Allow Companies to Showcase Cutting-edge Solutions
Alexandria, Va. - Dec. 1, 2003 - XML 2003, the world's largest XML conference
and exposition, will feature a trade show floor filled with key XML vendors
including Adobe Systems, Inc. (NASDAQ: ADBE), ArborText, BEA Systems, Inc.
(NASDAQ: BEAS), Document Management Solutions, Inc. (DMSI), Microsoft (NASDAQ:
MSFT),...
|
by: Steve Whitlatch |
last post by:
It may be me, or it may be the Linux implementation of XML Catalogs on
slackware. Whichever, please shed some light on this XML Catalog problem.
When using the --catalogs option, xmllint resolves all system entities
to local copies. No problem, for example:
**********
%:~/docbook-testdocs-1.1/tests> xmllint --noout --nonet --valid --catalogs book.001.xml
**********
| |
by: Stylus Studio |
last post by:
World's Most Advanced XML Schema Editor Adds Support for IBM AlphaWorks
XML Schema Quality Checker to Improve XML Schema Style and Quality
BEDFORD, MA -- 09/13/2005 -- Stylus Studio
(http://www.stylusstudio.com), the industry-leading provider of XML
development tools for advanced data integration, today announced new
support for IBM's alphaWorks XML Schema Quality Checker, furthering
solidifying its position as the provider of the...
|
by: laks |
last post by:
Hi
I have the following xsl stmt.
<xsl:for-each select="JOB_POSTINGS/JOB_POSTING
\">
<xsl:sort select="JOB_TITLE" order="ascending"/>
This works fine when I use it.
But when using multiple values in the where clause as below
|
by: jts2077 |
last post by:
I am trying to create a large nested XML object using E4X methods. The problem is the, the XML I am trying to create can only have xmlns set at the top 2 element levels. Such as:
<store
xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
<product sku="10050-1653" xmlns="http://www.store.com/xml/1.1.0.0/impex/catalog">
<sku>10050-1653</sku>
<name xml:lang="x-default">shop's Foie Gras</name>
<online>1</online>
...
|
by: =?Utf-8?B?YzY3NjIyOA==?= |
last post by:
Hi all,
I had a program and it always works fine and suddenly it gives me the
following message when a pass a xml file to our server program:
error code: -1072896680 reason: XML document must have a top level element.
line #: 0
I don't know if it is my xml file or it is something else?
Here is my client side program:
<%@ Language=vbScript%>
|
by: Jacker |
last post by:
Xpress Author for MS Word XML Documents
In.vision Research empowers knowledge workers to create complex XML
documents in Microsoft Word (2000-2003) with a normal Word experience.
Deploy XML authoring across the enterprise.
http://e.goozw.com/xml.htm
Powerful XML Editing Tool - XMLSPY
XMLSPY is a powerful XML tool for editing XML documents, XML schema,
DTDs, XSL/XSLT stylesheets, SOAP applications, debugging Web services
and more....
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |