mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
[Bug #1349316] Show how to use XML-RPC through a proxy
This commit is contained in:
parent
ef1b50de6c
commit
432be36056
1 changed files with 27 additions and 0 deletions
|
@ -355,3 +355,30 @@ try:
|
|||
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}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue