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 James Crowther
Recipients James Crowther, ned.deily
Date 2017-03-03.00:53:09
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <05C39109-3E9D-4608-80C0-E2CABD03BAB0@gmail.com>
In-reply-to <1488501673.57.0.239287963128.issue29705@psf.upfronthosting.co.za>
Content
Hi Ned, 
	Currently running 10.12.3. and output is as follows

Jamess-MacBook-pro:crowdrender_repository jamesmac$ python3.5
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> hostname = socket.gethostname()
>>> socket.getaddrinfo(hostname, None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
>>> 

This is a commonly prescribed method of resolving the ip address of your own machine on a LAN, also if I try another machines hostname which is on the local network, I get the same result. 

As for the experiments you tried, these do work, but that is not what I want to use the socket library for, I want to query the IP address of hosts on the LAN, localhost is no use to me, its just the loop back address.

I have a windows machine on my network and its hostname is James-PC, if i do

socket.getaddrinfo(“James-PC”)

I get the same error. This works if I reboot the mac (the same one that is having the issues) into linux and run the exact same command. I get the expected output from getaddrinfo. 

So, how come this approach doesn’t work on my mac? Also why are others having the same issue with Yosemite and sierra, this is not just me that is reporting this odd behaviour too. I’ve seen it in other forums.

Kind Regards

James

> On 3 Mar 2017, at 11:41 am, Ned Deily <report@bugs.python.org> wrote:
> 
> 
> Ned Deily added the comment:
> 
> Sorry, I can't reproduce that behavior with my macOS 10.12, 10.11, or 10.10 systems if the hostname is a valid string including "localhost".  If the string is empty or hostname is None, then I see Errno 8.
> 
> $ /usr/local/bin/python3.6
> Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13)
> [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import socket
>>>> hostname = 'python.org'
>>>> socket.getaddrinfo(hostname, None)
> [(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('23.253.135.79', 0)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('23.253.135.79', 0)), (<AddressFamily.AF_INET6: 30>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('2001:4802:7901::e60a:1375:0:6', 0, 0, 0)), (<AddressFamily.AF_INET6: 30>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('2001:4802:7901::e60a:1375:0:6', 0, 0, 0))]
>>>> hostname = "localhost"
>>>> socket.getaddrinfo(hostname, None)
> [(<AddressFamily.AF_INET6: 30>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('::1', 0, 0, 0)), (<AddressFamily.AF_INET6: 30>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('::1', 0, 0, 0)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('127.0.0.1', 0)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('127.0.0.1', 0))]
>>>> hostname = ""
>>>> socket.getaddrinfo(hostname, None)
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 743, in getaddrinfo
>    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
> socket.gaierror: [Errno 8] nodename nor servname provided, or not known
> 
> Perhaps there is something different about your hostname configuration on your Mac?  macOS has some unusual ways of configuring the hostname resolutions.  I don't have time at the moment to investigate further.  But Python's socket module interfaces tend to be very thin wrappers around the underlying OS provided APIs.  Perhaps you could test with a small C program that does the equivalent.
> 
> ----------
> 
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue29705>
> _______________________________________
History
Date User Action Args
2017-03-03 00:53:10James Crowthersetrecipients: + James Crowther, ned.deily
2017-03-03 00:53:09James Crowtherlinkissue29705 messages
2017-03-03 00:53:09James Crowthercreate