XML-RPC and firewall [solution]
Jeffrey Kunce
Jeffrey.Kunce at p98.f112.n480.z2.fidonet.org
Fri Jul 2 18:08:19 EDT 1999
More information about the Python-list mailing list
Fri Jul 2 18:08:19 EDT 1999
- Previous message (by thread): How do you make clickable Python/Win9x scripts?
- Next message (by thread): XML-RPC and firewall [solution]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: "Jeffrey Kunce" <kuncej at mail.conservation.state.mo.us> --=_693F2E73.E584ED6B Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I have been playing with XML-RPC on my intranet, but found that Fredrik's xmlrpclib.py wouldn't talk to external=20 servers through our firewall. Since urllib has proxy-server support built-in, I wrote a=20 urllib-based transport plugin for xmlrpclib.py (attached). Now I can speak XML-RPC with the rest of the world :-) Testing on this has been minimal - use at your own risk. If it checks out, maybe /F will include it in the distribution. --Jeff --=_693F2E73.E584ED6B Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xmlrpc_urllib_transport.py" '''\ urllib-based transport plugin for xmlrpclib.py (with test code) xmlrpc_urllib_transport.py jjk 07/02/99 001 from xmlrpc_test_urllib.py 002 urllib transport was needed to get past proxy server for xmlrpclib __version__ =3D "0.9.8" **************************** *** USE AT YOUR OWN RISK *** **************************** ''' import xmlrpclib class UrllibTransport(xmlrpclib.Transport): '''Handles an HTTP transaction to an XML-RPC server via urllib (urllib includes proxy-server support) jjk 07/02/99''' def request(self, host, handler, request_body): '''issue XML-RPC request jjk 07/02/99''' import urllib urlopener =3D urllib.FancyURLopener() urlopener.addheaders =3D [('User-agent', self.user_agent)] # probably should use appropriate 'join' methods instead = of 'http://'+host+handler f =3D urlopener.open('http://'+host+handler, request_body) return(self.parse_response(f)) def test(): '''test UrllibTransport for xmlrpclib Use proxy for external address, no proxy for local address jjk 07/02/99''' import os print 'testing xmlrpc_urllib_transport.py' raw_input('start xmlrpcserver.py (test mode) on local machine, = then press enter') testhosts =3D [ (0, "http://localhost:8000"), # don't use proxy, = local host #(0, "http://mdcmap.mocons.gov:8000"), # don't use = proxy, another host on local network (1, "http://betty.userland.com"), #use proxy, = userland's XML-RPC server ] try: proxies =3D os.environ['http_proxy'] except KeyError: proxies =3D None for useproxy, host in testhosts: print=20 print 'testing host:', host if (useproxy):=20 if (proxies): os.environ['HTTP_PROXY'] =3D proxies else: try: del os.environ['HTTP_PROXY'] except KeyError: pass server =3D xmlrpclib.Server(host, transport=3DUrllibTranspo= rt()) print server try: print server.examples.getStateName(41) except xmlrpclib.Error, v: print "ERROR", v =09 if (__name__=3D=3D'__main__'): import pdb test() --=_693F2E73.E584ED6B--
- Previous message (by thread): How do you make clickable Python/Win9x scripts?
- Next message (by thread): XML-RPC and firewall [solution]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list