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.

classification
Title: The example-code for making XML-RPC requests through proxy, fail!
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: docs@python Nosy List: ankostis, berker.peksag, docs@python
Priority: normal Keywords:

Created on 2015-09-12 12:08 by ankostis, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg250518 - (view) Author: Kostis Anagnostopoulos (ankostis) * Date: 2015-09-12 12:08
The example code provided at the bottom of the reference-page: 
  https://docs.python.org/2/library/xmlrpclib.html#example-of-client-usage
for making XML-RPC requests through a proxy by defining a custom transport fails (at least) in python-3.4!

Obviously it has been kept intact from `xmlrpclib` python-2 but `xmlrpc.client` API has changed and consequently the code fails.
Here is a IPython session demonstratin the problem:

    >>> 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.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 = xmlrpc.client.Server('http://time.xmlrpc.com/RPC2', transport=p)
    >>> print(server.currentTime.getCurrentTime())
    Traceback (most recent call last):
      File "D:\Apps\WinPython-64bit-3.4.3.4\python-3.4.3.amd64\lib\site-packages\IPython\core\interactiveshell.py", line 3035, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-43-7f4e26b6cd8f>", line 1, in <module>
        print(server.currentTime.getCurrentTime())
      File "D:\Apps\WinPython-64bit-3.4.3.4\python-3.4.3.amd64\lib\xmlrpc\client.py", line 1098, in __call__
        return self.__send(self.__name, args)
      File "D:\Apps\WinPython-64bit-3.4.3.4\python-3.4.3.amd64\lib\xmlrpc\client.py", line 1437, in __request
        verbose=self.__verbose
      File "D:\Apps\WinPython-64bit-3.4.3.4\python-3.4.3.amd64\lib\xmlrpc\client.py", line 1140, in request
        return self.single_request(host, handler, request_body, verbose)
      File "D:\Apps\WinPython-64bit-3.4.3.4\python-3.4.3.amd64\lib\xmlrpc\client.py", line 1152, in single_request
        http_conn = self.send_request(host, handler, request_body, verbose)
    TypeError: send_request() takes 4 positional arguments but 5 were given
msg260684 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-02-22 15:11
This has been fixed in cf842a8ccb77. Thank you for reporting this, Kostis!
History
Date User Action Args
2022-04-11 14:58:20adminsetgithub: 69267
2016-02-22 15:11:34berker.peksagsetstatus: open -> closed

versions: - Python 3.4
nosy: + berker.peksag

messages: + msg260684
resolution: out of date
stage: needs patch -> resolved
2015-09-15 23:00:25rhettingersettitle: The example-code for making XLM-RPC requests through proxy, fail! -> The example-code for making XML-RPC requests through proxy, fail!
2015-09-15 21:38:05berker.peksagsetstage: needs patch
type: behavior
components: - Demos and Tools
versions: + Python 3.5, Python 3.6
2015-09-12 12:08:35ankostiscreate