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

Discussion in 'Python' started by Eric Brunel, Oct 27, 2003.

  1. Eric Brunel

    Eric Brunel Guest

    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
     
    Eric Brunel, Oct 27, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fortepianissimo

    timeout in socket.gethostbyname()?

    Fortepianissimo, Dec 7, 2003, in forum: Python
    Replies:
    1
    Views:
    1,401
    Fortepianissimo
    Dec 8, 2003
  2. Andrew DeFaria

    If gethostbyname fails it never recovers

    Andrew DeFaria, Oct 5, 2006, in forum: Perl
    Replies:
    2
    Views:
    2,327
    Andrew DeFaria
    Oct 6, 2006
  3. 'gethostbyname' fails Please Help

    , Jul 24, 2008, in forum: C Programming
    Replies:
    4
    Views:
    417
  4. Lie Ryan
    Replies:
    1
    Views:
    898
    Nobody
    Jul 26, 2009
  5. Andrew DeFaria

    If gethostbyname fails it never recovers

    Andrew DeFaria, Oct 6, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    199
    Peter J. Holzer
    Oct 7, 2006
Loading...

Share This Page