Python 2.3: socket.gethostbyname(socket.gethostname()) fails?

Eric Brunel eric.brunel at pragmadev.N0SP4M.com
Mon Oct 27 11:21:39 EST 2003


Hi all,

I just compiled Python 2.3.2 on Linux Mandrake 8.0, upgrading from Python 2.1. I 
have one problem that I can't figure out: when I wanted to get "the" IP address 
of the current host with Python 2.1, I did:

Python 2.1.1 (#12, Apr 10 2002, 17:52:08)
[GCC 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)] on linux2
Type "copyright", "credits" or "license" for more information.
 >>> import socket
 >>> socket.gethostbyname(socket.gethostname())
'192.168.1.1'

I know it just returns one of the IP addresses of the current host, but it was 
OK for what I did with it. Doing the same thing with Python 2.3, I get:

Python 2.3.2 (#1, Oct 27 2003, 15:34:53)
[GCC 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> import socket
 >>> socket.gethostbyname(socket.gethostname())
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
socket.gaierror: (-2, 'Name or service not known')

Is it a bug? I saw I can get the same information via getaddrinfo, then 
getnameinfo, but why doesn't gethostbyname work in this case?
-- 
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com





More information about the Python-list mailing list