我目前正在尝试将XMLRPC请求发送到远程服务器,但是无法解决抛出的错误。
我需要能够使用我公司的代理服务器运行XMLRPC请求,因此我转向文档并尝试实施他们的建议以应对这种情况:
import http.client
import xmlrpc.client
class ProxiedTransport(xmlrpc.client.Transport):
def set_proxy(self, host, port=None, headers=None):
self.proxy = host, port
self.proxy_headers = headers
def make_connection(self, host):
connection = http.client.HTTPConnection(*self.proxy)
connection.set_tunnel(host, headers=self.proxy_headers)
self._connection = host, connection
return connection
transport = ProxiedTransport()
transport.set_proxy('http://company.net', port = XXXX)
server = xmlrpc.client.ServerProxy('http://betty.userland.com', transport=transport)
server.system.listMethods()
在上面的示例中,我在.set_proxy和xmlrpc.client.ServerProxy下输入了虚拟输入。
当我运行此代码或公司代理后面的任何XMLRPC代码时,会遇到以下错误:
Traceback (most recent call last):
File "<ipython-input-21-94e0b846ed28>", line 1, in <module>
server.system.listMethods()
File "C:\Users\hj6\AppData\Local\Continuum\anaconda3\lib\xmlrpc\client.py", line 1112, in __call__
return self.__send(self.__name, args)
File "C:\Users\hj6\AppData\Local\Continuum\anaconda3\lib\xmlrpc\client.py", line 1452, in __request
verbose=self.__verbose
File "C:\Users\hj6\AppData\Local\Continuum\anaconda3\lib\xmlrpc\client.py", line 1154, in request
return self.single_request(host, handler, request_body, verbose)
File "C:\Users\hj6\AppData\Local\Continuum\anaconda3\lib\xmlrpc\client.py", line 1166, in single_request
http_conn = self.send_request(host, handler, request_body, verbose)
File "C:\Users\hj6\AppData\Local\Continuum\anaconda3\lib\xmlrpc\client.py", line 1279, in send_request
self.send_content(connection, request_body)
File "C:\Users\hj6\AppData\Local\Continuum\anaconda3\lib\xmlrpc\client.py", line 1309, in send_content
connection.endheaders(request_body)
File "C:\Users\hj6\AppData\Local\Continuum\anaconda3\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\hj6\AppData\Local\Continuum\anaconda3\lib\http\client.py", line 1016, in _send_output
self.send(msg)
File "C:\Users\hj6\AppData\Local\Continuum\anaconda3\lib\http\client.py", line 956, in send
self.connect()
File "C:\Users\hj6\AppData\Local\Continuum\anaconda3\lib\http\client.py", line 928, in connect
(self.host,self.port), self.timeout, self.source_address)
File "C:\Users\hj6\AppData\Local\Continuum\anaconda3\lib\socket.py", line 707, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Users\hj6\AppData\Local\Continuum\anaconda3\lib\socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
gaierror: [Errno 11001] getaddrinfo failed
文档中没有提供有关如何解决此问题的帮助,我在构造HTTP请求方面也不是很了解,这使得此问题难以解决。
通过在线研究错误“ gaierror:[Errno 11001]”,我发现许多帖子都在讨论它与我的套接字配置有关,但我不知道如何在此背景下进行更改XMLRPC请求。有人对如何解决/进一步解决此问题有建议吗?