New submission from Attila Vangel: Go to https://docs.python.org/3/library/xmlrpc.client.html Under '21.26.8. Example of Client Usage' -> 'To access an XML-RPC server through a HTTP proxy, you need to define a custom transport. The following example shows how:' copy the example code to a .py file (for me it is easier than REPL), e.g. xmlrpc_client_http_proxy_test.py
This is the example code: import xmlrpc.client, http.client class ProxiedTransport(xmlrpc.client.Transport): def set_proxy(self, proxy): self.proxy = proxy def make_connection(self, host): self.realhost = host h = http.client.HTTPConnection(self.proxy) return h def send_request(self, connection, handler, request_body, debug): 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 = xmlrpc.client.ServerProxy('http://time.xmlrpc.com/RPC2', transport=p) print(server.currentTime.getCurrentTime()) I changed the 'proxy-server:8080' to '10.144.1.11:8080' which is a valid HTTP/HTTPS proxy in company I work for. Try to run this code: $ python3 xmlrpc_client_http_proxy_test.py Traceback (most recent call last): File "xmlrpc_client_http_proxy_test.py", line 21, in <module> print(server.currentTime.getCurrentTime()) File "/usr/lib/python3.5/xmlrpc/client.py", line 1092, in __call__ return self.__send(self.__name, args) File "/usr/lib/python3.5/xmlrpc/client.py", line 1432, in __request verbose=self.__verbose File "/usr/lib/python3.5/xmlrpc/client.py", line 1134, in request return self.single_request(host, handler, request_body, verbose) File "/usr/lib/python3.5/xmlrpc/client.py", line 1146, in single_request http_conn = self.send_request(host, handler, request_body, verbose) File "xmlrpc_client_http_proxy_test.py", line 13, in send_request connection.putrequest("POST", 'http://%s%s' % (self.realhost, handler)) AttributeError: 'str' object has no attribute 'putrequest' Personally I don't like the idea of putting this amount of code to documentation: - as it seems, without automated tests running it, the code seems to rot, and gets outdated - I need to paste this boilerplate code to my application if I want this functionality. IMHO it would be much better to move this ProxiedTransport example code (after fixing it) to e.g. xmlrpc.client.HttpProxyTransport (or similar name) class. Details about python3: $ python3 Python 3.5.2 (default, Sep 10 2016, 08:21:44) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> ---------- assignee: docs@python components: Documentation files: xmlrpc_client_http_proxy_test.py messages: 278291 nosy: avangel, docs@python priority: normal severity: normal status: open title: xmlrpc.client HTTP proxy example code does not work type: crash versions: Python 3.5 Added file: http://bugs.python.org/file45010/xmlrpc_client_http_proxy_test.py _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28389> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com