[Python-checkins] commit of r41636 - python/trunk/Doc/lib/libxmlrpclib.tex

andrew.kuchling python-checkins at python.org
Thu Dec 8 15:54:21 CET 2005


Author: andrew.kuchling
Date: Thu Dec 8 15:54:20 2005
New Revision: 41636
Modified:
 python/trunk/Doc/lib/libxmlrpclib.tex
Log:
[Bug #1349316] Show how to use XML-RPC through a proxy
Modified: python/trunk/Doc/lib/libxmlrpclib.tex
==============================================================================
--- python/trunk/Doc/lib/libxmlrpclib.tex	(original)
+++ python/trunk/Doc/lib/libxmlrpclib.tex	Thu Dec 8 15:54:20 2005
@@ -355,3 +355,30 @@
 except Error, v:
 print "ERROR", v
 \end{verbatim}
+
+To access an XML-RPC server through a proxy, you need to define 
+a custom transport. The following example, 
+written by NoboNobo, % fill in original author's name if we ever learn it
+shows how:
+
+% Example taken from http://lowlife.jp/nobonobo/wiki/xmlrpcwithproxy.html
+\begin{verbatim}
+import xmlrpclib, httplib
+
+class ProxiedTransport(xmlrpclib.Transport):
+ def set_proxy(self, proxy):
+ self.proxy = proxy
+ def make_connection(self, host):
+ self.realhost = host
+	h = httplib.HTTP(self.proxy)
+	return h
+ def send_request(self, connection, handler, request_body):
+ connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler))
+ def send_host(self, connection, host):
+ connection.putheader('Host', self.realhost)
+
+p = ProxiedTransport()
+p.set_proxy('proxy-server:8080')
+server = xmlrpclib.Server('http://time.xmlrpc.com/RPC2', transport=p)
+print server.currentTime.getCurrentTime()
+\end{verbatim}


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /