473,237 Members | 1,393 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,237 software developers and data experts.

xmlrpc, extract data from http headers

I perform a XML-RPC call by calling xmlrpclibBasicAuth 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 3032
Milos Prudek wrote:
I perform a XML-RPC call by calling xmlrpclibBasicAuth 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
BasicAuthTransport 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
BasicAuthTransport 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
BasicAuthTransport 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.Transport):
def request(self, host, handler, request_body, verbose=0):
h = self.make_connection(host)
if verbose:
h.set_debuglevel(1)

self.send_request(h, handler, request_body)
self.send_host(h, host)
self.send_user_agent(h)
self.send_content(h, request_body)

errcode, errmsg, headers = h.getreply()

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

self.verbose = verbose

cookies = self.get_cookies(headers)

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

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

return response, cookies

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

server = xmlrpclib.ServerProxy("http://localhost:8000",
transport=CookieTransport())
result, cookies = server.something.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
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>...
4
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...
1
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...
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...
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...
1
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...
0
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
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...
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: ...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.