473,766 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xmlrpc, extract data from http headers

I perform a XML-RPC call by calling xmlrpclibBasicA uth which in turn calls
xmlrpclib. This call of course sends a HTTP request with correct HTTP
headers. The response is correctly parsed by xmlrpclib, and I get my desired
values.

However, I also need to get the raw HTTP headers from the HTTP response. There
is a cookie in the HTTP response and I need to read that cookie.

How could I do that?

--
Milos Prudek
Sep 15 '06 #1
5 3069
Milos Prudek wrote:
I perform a XML-RPC call by calling xmlrpclibBasicA uth which in turn calls
xmlrpclib. This call of course sends a HTTP request with correct HTTP
headers. The response is correctly parsed by xmlrpclib, and I get my desired
values.

However, I also need to get the raw HTTP headers from the HTTP response. There
is a cookie in the HTTP response and I need to read that cookie.

How could I do that?
Overload the _parse_response method of Transport in your
BasicAuthTransp ort and extract headers from raw response. See the
source of xmlrpclib.py in the standard library for details.

cheers,
fw

Sep 15 '06 #2
Overload the _parse_response method of Transport in your
BasicAuthTransp ort and extract headers from raw response. See the
source of xmlrpclib.py in the standard library for details.
Thank you.

I am a bit of a false beginner in Python. I have written only short scripts. I
want to read "Dive into Python" to improve my knowledge. Your advice is
perfect. It is my fault that I need a little more guidance.

I am not sure how the headers will be passed from Transport to the instance of
ServerProxy. That is, if I change the _parse_response method, how do I
retreive the headers using the ServerProxy command?
--
Milos Prudek
Sep 16 '06 #3
Milos Prudek wrote:
Overload the _parse_response method of Transport in your
BasicAuthTransp ort and extract headers from raw response. See the
source of xmlrpclib.py in the standard library for details.

Thank you.

I am a bit of a false beginner in Python. I have written only short scripts. I
want to read "Dive into Python" to improve my knowledge. Your advice is
perfect. It is my fault that I need a little more guidance.

I am not sure how the headers will be passed from Transport to the instance of
ServerProxy. That is, if I change the _parse_response method, how do I
retreive the headers using the ServerProxy command?
Erm, now I see that my previous response was incorrect, sorry. The
headers are not passed to the _parse_response method.

A better solution would be to extract cookies from headers in the
request method and return them with response (see the code below). I
still wonder if there is an easy way to use CookieJar from cookielib
with xmlrpclib.

class CookieTransport (xmlrpclib.Tran sport):
def request(self, host, handler, request_body, verbose=0):
h = self.make_conne ction(host)
if verbose:
h.set_debugleve l(1)

self.send_reque st(h, handler, request_body)
self.send_host( h, host)
self.send_user_ agent(h)
self.send_conte nt(h, request_body)

errcode, errmsg, headers = h.getreply()

if errcode != 200:
raise ProtocolError(
host + handler,
errcode, errmsg,
headers
)

self.verbose = verbose

cookies = self.get_cookie s(headers)

try:
sock = h._conn.sock
except AttributeError:
sock = None

response = self._parse_res ponse(h.getfile (), sock)
if len(response) == 1:
response = response[0]

return response, cookies

def _get_cookies(se lf, headers):
import Cookie
c = []
for v in headers.gethead ers('set-cookie'):
c.append(Cookie .SimpleCookie(v ))
return c

server = xmlrpclib.Serve rProxy("http://localhost:8000" ,
transport=Cooki eTransport())
result, cookies = server.somethin g.call()
best,
fw

Sep 16 '06 #4
A better solution would be to extract cookies from headers in the
request method and return them with response (see the code below). I
Full solution! Wow! Thank you very much. I certainly do not deserve such
kindness. Thanks a lot Filip!

--
Milos Prudek
Sep 19 '06 #5
Milos Prudek wrote:
A better solution would be to extract cookies from headers in the
request method and return them with response (see the code below). I

Full solution! Wow! Thank you very much. I certainly do not deserve such
kindness. Thanks a lot Filip!
Glad to help. All in all this is the purpose of this group, isn't it?

cheers,
fw

Sep 19 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1835
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> <script src="jsolait/lib/urllib.js"></script> <script src="jsolait/lib/xml.js"></script>
4
3809
by: Roger Binns | last post by:
I have just spent several weeks mashing xmlrpc, httplib and SSL (from M2Crypto) to work together. The current standard library has several problems: - Builtin SSL is pretty much useless if you actually care about security - Poor HTTP authentication support - No server side stuff (SSL, HTTP authentication etc) - Pathological coding to ensure that at most one request is sent on a connection, rather than reusing an already open
1
2067
by: Thomas | last post by:
Hi, Sorry for the stupid subject, but here it goes: I need a simple Webserver which can 1. serve xmlrpc-methods 2. send multicast packets on local network to get response from a similar server acting as master on the given network 3. somehow serve a single file using simple http/webserver methods to
1
3214
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 the header. Since the XML-RPC specification requires this header to be present in the server response, some libraries (notably: libxmlrpc++) choke on this. For clarity, here's a (simple) server (slightly altered from:...
8
3738
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 I get/create rapidly the ..pem files (the key and cert). Any help? Thanks
1
3255
by: Thomas Liesner | last post by:
Hi all, this may have been asked before, but as a newbie with xmlrpc i can't find any suitable info on that. Sorry. I am trying to write a simple xmlrpc-client in python and the server i am trying to receive data from requires http auth digest. The info on xmlrpclib covers auth basic thrugh url econding such as "user:pass@server", but no auth digest. Is there any other library i could use for that or can i write some sort
0
1154
by: nil111181 | last post by:
hello i got this error Traceback (most recent call last): File "import_data.py", line 303, in ? imp._import(); File "import_data.py", line 265, in _import
1
3163
by: Sean Davis | last post by:
I would like to set up a server that takes XMLRPC requests and processes them asynchronously. The XMLRPC server part is trivial in python. The job processing part is the part that I am having trouble with. I have been looking at how to use threadpool, but I can't see how to get that working. I would like to have the XMLRPC part of things do something like: def method1(a,b,c): jobid=workRequest(long_method1,) return(jobid)
0
2751
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: ext/xmlrpc/.libs/xmlrpc-epi-php.o(.text+0x359): In function `set_zval_xmlrpc_type': /php-5.2.5/ext/xmlrpc/xmlrpc-epi-php.c:1313: undefined reference to `XMLRPC_CreateValueDateTime_ISO8601'
0
10168
Oralloy
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...
0
10008
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 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...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8833
agi2029
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...
1
7381
isladogs
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...
0
6651
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();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.