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: socket.gaierror before ProtocolError for xmlrpc.client
Type: behavior Stage: test needed
Components: Documentation, Library (Lib) Versions: Python 3.1, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: ezio.melotti, georg.brandl, loewis, mnewman
Priority: normal Keywords:

Created on 2010-01-29 01:18 by mnewman, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg98493 - (view) Author: Michael Newman (mnewman) Date: 2010-01-29 01:18
Following the example in Section 20.23.5. ProtocolError Objects of:
http://docs.python.org/3.1/library/xmlrpc.client.html
It implies that an invalid URL will give raise an xmlrpc.client.ProtocolError. Instead I'm getting a socket.gaierror instead. (I also tried using the google address to show tat ProtocolError is working correctly if a real URL is used, but doesn't offer XML-RPC services.) This similarly is happening for xmlrpclib on Python 2.6.

Is this a bug or documentation mistake?

Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xmlrpc.client
>>> proxy = xmlrpc.client.ServerProxy("http://invalidaddress/")
>>> proxy.some_method()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\python31\lib\xmlrpc\client.py", line 1029, in __call__
    return self.__send(self.__name, args)
  File "C:\python31\lib\xmlrpc\client.py", line 1271, in __request
    verbose=self.__verbose
  File "C:\python31\lib\xmlrpc\client.py", line 1058, in request
    http_conn = self.send_request(host, handler, request_body, verbose)
  File "C:\python31\lib\xmlrpc\client.py", line 1144, in send_request
    connection.request("POST", handler, request_body, headers)
  File "C:\python31\lib\http\client.py", line 918, in request
    self._send_request(method, url, body, headers)
  File "C:\python31\lib\http\client.py", line 956, in _send_request
    self.endheaders(body)
  File "C:\python31\lib\http\client.py", line 914, in endheaders
    self._send_output(message_body)
  File "C:\python31\lib\http\client.py", line 768, in _send_output
    self.send(msg)
  File "C:\python31\lib\http\client.py", line 716, in send
    self.connect()
  File "C:\python31\lib\http\client.py", line 698, in connect
    self.timeout)
  File "C:\python31\lib\socket.py", line 292, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11001] getaddrinfo failed
>>> proxy = xmlrpc.client.ServerProxy("http://www.google.com/")
>>> proxy.some_method()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\python31\lib\xmlrpc\client.py", line 1029, in __call__
    return self.__send(self.__name, args)
  File "C:\python31\lib\xmlrpc\client.py", line 1271, in __request
    verbose=self.__verbose
  File "C:\python31\lib\xmlrpc\client.py", line 1065, in request
    dict(resp.getheaders())
xmlrpc.client.ProtocolError: <ProtocolError for www.google.com/: 405 Method Not Allowed>
>>>

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xmlrpclib
>>> proxy = xmlrpclib.ServerProxy("http://invalidaddress/")
>>> proxy.some_method()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\python26\lib\xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "C:\python26\lib\xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "C:\python26\lib\xmlrpclib.py", line 1235, in request
    self.send_content(h, request_body)
  File "C:\python26\lib\xmlrpclib.py", line 1349, in send_content
    connection.endheaders()
  File "C:\python26\lib\httplib.py", line 892, in endheaders
    self._send_output()
  File "C:\python26\lib\httplib.py", line 764, in _send_output
    self.send(msg)
  File "C:\python26\lib\httplib.py", line 723, in send
    self.connect()
  File "C:\python26\lib\httplib.py", line 704, in connect
    self.timeout)
  File "C:\python26\lib\socket.py", line 500, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 11001] getaddrinfo failed
>>> proxy = xmlrpclib.ServerProxy("http://www.google.com/")
>>> proxy.some_method()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\python26\lib\xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "C:\python26\lib\xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "C:\python26\lib\xmlrpclib.py", line 1243, in request
    headers
xmlrpclib.ProtocolError: <ProtocolError for www.google.com/: 405 Method Not Allowed>

I also checked Python 3.1 on Linux:

Python 3.1.1 (r311:74480, Oct 18 2009, 19:21:53) [GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xmlrpc.client
>>> proxy = xmlrpc.client.ServerProxy("http://invalidaddress/")
>>> proxy.some_method()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.1/xmlrpc/client.py", line 1029, in __call__
    return self.__send(self.__name, args)
  File "/usr/local/lib/python3.1/xmlrpc/client.py", line 1271, in __request
    verbose=self.__verbose
  File "/usr/local/lib/python3.1/xmlrpc/client.py", line 1058, in request
    http_conn = self.send_request(host, handler, request_body, verbose)
  File "/usr/local/lib/python3.1/xmlrpc/client.py", line 1144, in send_request
    connection.request("POST", handler, request_body, headers)
  File "/usr/local/lib/python3.1/http/client.py", line 918, in request
    self._send_request(method, url, body, headers)
  File "/usr/local/lib/python3.1/http/client.py", line 956, in _send_request
    self.endheaders(body)
  File "/usr/local/lib/python3.1/http/client.py", line 914, in endheaders
    self._send_output(message_body)
  File "/usr/local/lib/python3.1/http/client.py", line 768, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.1/http/client.py", line 716, in send
    self.connect()
  File "/usr/local/lib/python3.1/http/client.py", line 698, in connect
    self.timeout)
  File "/usr/local/lib/python3.1/socket.py", line 292, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known
>>> proxy = xmlrpc.client.ServerProxy("http://www.google.com/")
>>> proxy.some_method()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.1/xmlrpc/client.py", line 1029, in __call__
    return self.__send(self.__name, args)
  File "/usr/local/lib/python3.1/xmlrpc/client.py", line 1271, in __request
    verbose=self.__verbose
  File "/usr/local/lib/python3.1/xmlrpc/client.py", line 1065, in request
    dict(resp.getheaders())
xmlrpc.client.ProtocolError: <ProtocolError for www.google.com/: 405 Method Not Allowed>
msg98495 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-01-29 01:51
FWIW it had the same behavior already on Python 2.4.
msg98571 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-01-30 17:57
Thanks, that example was indeed wrong.  ProtocolError is not meant to be raised if the HTTP connection to the specified URI can't even be made, e.g. for unknown hosts.  Fixed in r77858.
History
Date User Action Args
2022-04-11 14:56:57adminsetgithub: 52050
2010-01-30 17:57:54georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg98571
2010-01-29 01:51:32ezio.melottisetpriority: normal

nosy: + loewis, ezio.melotti
messages: + msg98495

stage: test needed
2010-01-29 01:18:20mnewmancreate