Python gethostbyname fails just one one machine.

Chris Angelico rosuav at gmail.com
Wed Dec 17 22:33:57 EST 2014


On Thu, Dec 18, 2014 at 2:21 PM,  <abhishes at gmail.com> wrote:
> I have many machines on which the following command returns nothing (but does not throw an error as well
>
> python -c 'import socket; socket.gethostbyname(socket.getfqdn())'
>
>
> but on just one machine. this command throws
>
> Traceback (most recent call last):
>   File "<string>", line 1, in <module>
> socket.gaierror: [Errno -3] Temporary failure in name resolution
>
>
> I searched the internet and most people had this problem because of a bad /etc/hosts file or /etc/sysconfig/network file
>
> but in my case this files are absolutely correct
>
> /etc/hosts
> 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
> ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
> 156.17.148.40 cm1work
> 156.17.148.41 hd1work
> 156.17.148.42 hd2work
> 156.17.148.43 hd3work
>
> /etc/sysconfig/network
> NETWORKING=yes
> HOSTNAME=h3work
> GATEWAY=156.17.148.1
>
> but this command just won't work

What you have here is a networking issue, not a Python one, so you may
well find you can't get the help you need here. But I'll try.

Have you checked /etc/nsswitch.conf? What about /etc/resolv.conf or
equivalent? What's the FQDN returned in the first step? If there's a
difference in any of those, it might give a clue.

If all else fails, try stracing the process:

strace python -c 'import socket; socket.gethostbyname(socket.getfqdn())'

and see if there are any obvious errors.

This is a bit of nutting out and analysis, so I wouldn't be surprised
if you get lots of wrong answers before you find the right one. It's
like Edison said (or is said to have said): you're finding a thousand
ways to NOT make a light bulb.

ChrisA



More information about the Python-list mailing list