[docs] [issue28389] xmlrpc.client HTTP proxy example code does not work
Attila Vangel
report at bugs.python.org
Sat Oct 8 09:33:00 EDT 2016
Attila Vangel added the comment:
Hi, thx for the quick turnaround.
I tried the proxy.py (on python 3.5) of course replacing 'YOUR_PROXY' with '10.144.1.11:8080' according to my environment.
python3 proxy.py
Traceback (most recent call last):
File "proxy.py", line 27, in <module>
print(server.examples.getStateName(41))
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 1147, in single_request
resp = http_conn.getresponse()
File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse
response.begin()
File "/usr/lib/python3.5/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.5/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.5/socket.py", line 575, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer
However, meanwhile I studied a bit the http.client API on how to use HTTP proxy, and I found set_tunnel() can do it. I had success by only overriding make_connection() in ProxiedTransport:
- copy current code of make_connection() from xmlrpc.client.Transport to ProxiedTransport (NOTE, this itself violates the DRY principle, but there is no better way to do it), change it slightly:
- create HTTPSConnection to the proxy (as I wanted to access a https URL)
- use .set_tunnel(chost) on this connection
I did not want to paste the code here, because
- I did not want to fill the 'PSF Contributor Agreement', at least yet
- it may be Python version specific solution.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28389>
_______________________________________
More information about the docs
mailing list