Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: xmlrpc, httplib and SSL (HTTP 1.1 XMLRPC client)

Reply
Thread Tools

Re: xmlrpc, httplib and SSL (HTTP 1.1 XMLRPC client)

 
 
Etienne Posthumus
Guest
Posts: n/a
 
      04-01-2004

On Mar 27, 2004, at 5:03 AM, Roger Binns wrote:
> However I was wondering if anyone was working on fixing the
> (IMHO horrible) mess and wants any moral support?


I wanted to do keep the connections on which my clients do XMLRPC calls
open, and after staring at the xmlrpclib.py source for a while, came up
with the class at the bottom of the message. Just thought I would post
it here in the spirit of sharing. You would use it like this:

import httplib, xmlrpclib
s = xmlrpclib.ServerProxy('http://SOMEURL',
transport=PersistTransport())

And then use as normal. When any error occurs, the connection is
closed, seems a bit pessimistic, but I didn't want to do anything more
fancy.

cheers,

Etienne Posthumus
---
http://www.mnemosyne.org/
Cultural Heritage Research
Python, Zope, XML expertise for hire.
Amsterdam, Nederland
----

class PersistTransport(xmlrpclib.Transport):
'''Provides a Transport for the xmlrpclib that uses httplib
supporting persistent connections
Does not close the connection after each request.
'''
connection = None

def request(self, host, handler, request_body, verbose=0):
if not self.connection:
host, extra_headers, x509 = self.get_host_info(host)
self.connection = httplib.HTTPConnection(host)
self.headers = {"User-Agent" : self.user_agent,
"Content-Type" : "text/xml",
"Accept": "text/xml"}
if extra_headers:
for key, item in extra_headers:
self.headers[key] = item

self.headers["Content-Length"] = str(len(request_body))
self.connection.request('POST', handler, request_body,
self.headers)
r = self.connection.getresponse()
if r.status != 200:
self.connection.close()
self.connection = None
raise xmlrpclib.ProtocolError( host + handler, r.status,
r.reason, '' )
data = r.read()
p, u = self.getparser()
p.feed(data)
p.close()
return u.close()


 
Reply With Quote
 
 
 
 
Roger Binns
Guest
Posts: n/a
 
      04-01-2004
> I wanted to do keep the connections on which my clients do XMLRPC calls
> open, and after staring at the xmlrpclib.py source for a while, came up
> with the class at the bottom of the message.


Are you sure you are actually getting persistent connections? The
code will auto-close and auto-open the connection even just keeping
the same HTTP connection object.

In order for the connection to not be auto-closed, the remote end
must return a HTTP/1.1 response (see httplib.HTTPResponse._check_close).

If your server end is Python, then it will always close the connection
unless the request was HTTP/1.1 *and* a 'Connection: keep-alive' header
was sent, which the Python client does not do.

The above is all true for Python 2.3. For 2.2 it does HTTP/1.0 IIRC
so you have no hope.

Roger


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python xmlrpc client with ssl client certificates and standard modules News123 Python 9 02-15-2012 01:04 PM
SSL and OpenSSL::SSL::SSLServer accept() born in USSR Ruby 2 09-27-2009 01:46 AM
XMLRPC and SSL Chaz Ginger Python 1 06-18-2007 09:40 PM
Maintain session between an SSL page and Non SSL page John Smith Java 0 10-05-2006 12:03 PM
webrick, ssl and non-ssl on the same port Pavel Smerk Ruby 3 08-15-2006 05:51 PM



Advertisments