This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author avangel
Recipients avangel, docs@python
Date 2016-10-08.11:53:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1475927614.18.0.277920882449.issue28389@psf.upfronthosting.co.za>
In-reply-to
Content
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.
>>>
History
Date User Action Args
2016-10-08 11:53:34avangelsetrecipients: + avangel, docs@python
2016-10-08 11:53:34avangelsetmessageid: <1475927614.18.0.277920882449.issue28389@psf.upfronthosting.co.za>
2016-10-08 11:53:34avangellinkissue28389 messages
2016-10-08 11:53:33avangelcreate