473,406 Members | 2,707 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,406 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 3043
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: ...
0
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
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
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,...
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...
0
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...
0
tracyyun
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...

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.