Dear all,
I'm writing an XML-RPC server which should be able to modify the
incoming request before dispatching it. In particular I wand to added
two fixed parameters to the method called: one is the client host
address, and the other is the user name provided as for Basic
Authentication ( http://us**@www.bla-bla.com).
To do this, at the present I've overwritten the do_POST method of
SimpleXMLRPCRequestHandler, including at a certain point this code:
.....
data = ''.join(L)
params, method = xmlrpclib.loads(data)
user = "unknown"
if self.headers.has_key('Authorization'):
# handle Basic authentication
(enctype, encstr) = self.headers.get('Authorization').split()
user, password = base64.standard_b64decode(encstr).split(':')
params = list(params)
params.append(self.address_string())
params.append(user)
params = tuple(params)
data = xmlrpclib.dumps(params, methodname=method)
(I slightly modified it to make it more readable at mail level)
It works, but I don't really like it because it completely overwrites
the do_POST method that in the future Python releases is going to
change (I verified it). Do you know a better way to do this?
Thanks in advance.
Luigi 6 1589
Luigi wrote:
Dear all,
I'm writing an XML-RPC server which should be able to modify the
incoming request before dispatching it. In particular I wand to added
two fixed parameters to the method called: one is the client host
address, and the other is the user name provided as for Basic
Authentication (http://us**@www.bla-bla.com).
To do this, at the present I've overwritten the do_POST method of
SimpleXMLRPCRequestHandler, including at a certain point this code:
....
data = ''.join(L)
params, method = xmlrpclib.loads(data)
user = "unknown"
if self.headers.has_key('Authorization'):
# handle Basic authentication
(enctype, encstr) = self.headers.get('Authorization').split()
user, password = base64.standard_b64decode(encstr).split(':')
params = list(params)
params.append(self.address_string())
params.append(user)
params = tuple(params)
data = xmlrpclib.dumps(params, methodname=method)
(I slightly modified it to make it more readable at mail level)
It works, but I don't really like it because it completely overwrites
the do_POST method that in the future Python releases is going to
change (I verified it). Do you know a better way to do this?
I would go for a slightly different approach: make your server have a
dispatch-method that delegates the calls to the underlying actual
implementation. But *before* that happens, extract the information as
above, and either
- prepend it to the argument list
- stuff it into threadlocal variables, and only access these if needed in
your implementation.
Diez
On 9 Set, 17:55, "Diez B. Roggisch" <de...@nospam.web.dewrote:
I would go for a slightly different approach: make your server have a
dispatch-method that delegates the calls to the underlying actual
implementation. But *before* that happens, extract the information as
above, and either
*- prepend it to the argument list
*- stuff it into threadlocal variables, and only access these if neededin
your implementation.
Diez
Are you suggesting me to overwrite the _dispatch(self, method, params)
method of SimpleXMLRPCDispatcher? I thought to this possibility, but
it only accepts "method" and "params" as arguments, so, as far as I
know, I have no way to get the user and host address to append.
Perhaps I've misunderstood your suggestion... in that case can you
post a short example?
Thank you very much!
Luigi
On Sep 9, 8:53*am, Luigi <luigipai...@libero.itwrote:
Dear all,
I'm writing an XML-RPC server which should be able to modify the
incoming request before dispatching it. In particular I wand to added
two fixed parameters to the method called: one is the client host
address, and the other is the user name provided as for Basic
Authentication (http://u...@www.bla-bla.com).
To do this, at the present I've overwritten the do_POST method of
SimpleXMLRPCRequestHandler, including at a certain point this code:
....
data = ''.join(L)
params, method = xmlrpclib.loads(data)
user = "unknown"
if self.headers.has_key('Authorization'):
* # handle Basic authentication
* (enctype, encstr) = *self.headers.get('Authorization').split()
* user, password = base64.standard_b64decode(encstr).split(':')
params = list(params)
params.append(self.address_string())
params.append(user)
params = tuple(params)
data = xmlrpclib.dumps(params, methodname=method)
(I slightly modified it to make it more readable at mail level)
It works, but I don't really like it because it completely overwrites
the do_POST method that in the future Python releases is going to
change (I verified it). Do you know a better way to do this?
Thanks in advance.
Luigi
I actually wrote a wsgi module for almost this -exact- use case
(having to prepend a user/password to the method calls). The simple
rpc server and dispatchers didn't give me enough control over the
behavior, so I had to reimplement all the logic surround the loads/
dumps calls, and eventually that just turned into the bulk of the
whole SimpleXMLRPCServer module. There's a lot of tight coupling in
the _dispatch method, so you'll have to override, monkey patch, or
reimplement it. lu**********@gmail.com schrieb:
On 9 Set, 17:55, "Diez B. Roggisch" <de...@nospam.web.dewrote:
>I would go for a slightly different approach: make your server have a dispatch-method that delegates the calls to the underlying actual implementation. But *before* that happens, extract the information as above, and either
- prepend it to the argument list
- stuff it into threadlocal variables, and only access these if needed in your implementation.
Diez
Are you suggesting me to overwrite the _dispatch(self, method, params)
method of SimpleXMLRPCDispatcher? I thought to this possibility, but
it only accepts "method" and "params" as arguments, so, as far as I
know, I have no way to get the user and host address to append.
Perhaps I've misunderstood your suggestion... in that case can you
post a short example?
Ah, darn. Yes, you are right of course, the information itself is not
available, as you don't have access to the request. I gotta ponder this
a bit more.
Diez
On Sep 10, 2:04*pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
luigi.pai...@gmail.com schrieb:
On 9 Set, 17:55, "Diez B. Roggisch" <de...@nospam.web.dewrote:
I would go for a slightly different approach: make your server have a
dispatch-method that delegates the calls to the underlying actual
implementation. But *before* that happens, extract the information as
above, and either
*- prepend it to the argument list
*- stuff it into threadlocal variables, and only access these if needed in
your implementation.
Diez
Are you suggesting me to overwrite the _dispatch(self, method, params)
method of SimpleXMLRPCDispatcher? I thought to this possibility, but
it only accepts "method" and "params" as arguments, so, as far as I
know, I have no way to get the user and host address to append.
Perhaps I've misunderstood your suggestion... in that case can you
post a short example?
Ah, darn. Yes, you are right of course, the information itself is not
available, as you don't have access to the request. I gotta ponder this
a bit more.
Diez
Because he wants to insert parameters at the very start, he can
probably get away with modifying the xml directly. Just find the
position of the <params(i think thats the tag) and insert the xml
you need after it. Its pretty dirty, but would work. The wire format
isn't that complicated.
On 11 Set, 18:45, Richard Levasseur <richard...@gmail.comwrote:
Because he wants to insert parameters at the very start, he can
probably get away with modifying the xml directly. *Just find the
position of the <params(i think thats the tag) and insert the xml
you need after it. *Its pretty dirty, but would work. *The wire format
isn't that complicated.
I think this is exactly what I do... isn't it? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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>...
|
by: Juan Carlos CORUÑA |
last post by:
Hello all,
I'm trying to create a COM Server with an embedded xmlrpc server.
Here is way it must work:
- The client application (programmed with a COM capable language)
instantiates my COM...
|
by: Michael Urman |
last post by:
Hi. I'm a user of python for about 3 years now. I've written a
client-server application that uses SimpleXMLRPCServer and
xmlrpclib.ServerProxy to communicate. It's intended to be used by a...
|
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...
|
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...
|
by: elyob |
last post by:
Hi, I've got --with-xmlrpc option in my php.ini and can see on my phpinfo
page. Now, how do I include this in some code? So far I've been downloading
xmlrpc into a folder and just calling it from...
|
by: Manuel |
last post by:
Hello
I need a xmlrpc lib for c++. I know two: xmlrpc++ and xmlrpc-c. But i
don't know that it is best for me.
I am developing an application in c++. I read that the xmlrpc-c lib is
in C and wrap...
|
by: fortepianissimo |
last post by:
I have a simple xmlrpc server/client written in Python, and the client
throws a list of lists to the server and gets back a list of lists.
This runs without a problem.
I then wrote a simple Java...
|
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:
...
|
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
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
|
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...
|
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...
| |