Fixing xmlrpclib

Ng Pheng Siong ngps at madcap.dyndns.org
Fri May 5 11:44:59 EDT 2000


According to 5ÛHH575-UAZWKVVP-7H2H48V3 <thomas at cintra.no>:
> Trying out the xmlrpclib with my local zope-site. Read in the How-To
> by Amos, located at zope.org, that the pythonware "version"  of
> xmlrpclib needed some fixing,

Amos's tutorial talks about creating a BasicAuthTransport class
derived from xmlrpclib.Transport. Just stick his code at the
end of xmlrpclib.py.

Alternatively, you can patch xmlrpclib.Transport directly:

--- xmlrpclib.py.orig	Fri May  5 23:34:08 2000
+++ xmlrpclib-auth.py	Fri May  5 23:36:16 2000
@@ -555,18 +555,25 @@
 
     def request(self, host, handler, request_body):
         # issue XML-RPC request
+        user_passwd, host_port = urllib.splituser(host)
+        _host, _port = urllib.splitport(host_port)
 
         import httplib
-        h = httplib.HTTP(host)
+        h = httplib.HTTP(_host, int(_port))
         h.putrequest("POST", handler)
 
         # required by HTTP/1.1
-        h.putheader("Host", host)
+        h.putheader("Host", _host)
 
         # required by XML-RPC
         h.putheader("User-Agent", self.user_agent)
         h.putheader("Content-Type", "text/xml")
         h.putheader("Content-Length", str(len(request_body)))
+
+        # Authorisation.
+        if user_passwd is not None:
+            auth=string.strip(base64.encodestring(user_passwd))
+            h.putheader('Authorization', 'Basic %s' % auth)
 
         h.endheaders()
 

FWIW, I have also a patch to let xmlrpclib talk through
a http proxy. Let me know if you want it.

FWIW2, M2Crypto comes with xmlrpclib2.py, which extends 
xmlrpclib to work over https. 

Cheers.

-- 
Ng Pheng Siong <ngps at post1.com> * http://www.post1.com/home/ngps




More information about the Python-list mailing list