开发者

socket.getaddrinfo fails on one machine; works on another apparently-identical one. Why?

开发者 https://www.devze.com 2023-01-07 18:37 出处:网络
I\'ve got a laptop and a desktop, both running Ubuntu 10.04, both running the stock Python 2.6.5 that comes with Ubuntu.

I've got a laptop and a desktop, both running Ubuntu 10.04, both running the stock Python 2.6.5 that comes with Ubuntu.

On the laptop, the following program

#!/usr/bin/env python
import socket
print(socket.getaddrinfo("localhost", 8025, 0, socket.SOCK_STREAM))

works -- i.e., it prints out some stuff without开发者_JAVA技巧 getting an error.

The stuff, in fact, is:

[(10, 1, 6, '', ('::1', 8025, 0, 0)), (2, 1, 6, '', ('127.0.0.1', 8025))]

(That's one bunch of IPv6 data, and one bunch of IPv4 data.)

However, on the other box, the same program does this:

Traceback (most recent call last):
  File "socktest.py", line 5, in <module>
    print(socket.getaddrinfo("localhost", 8025, 0, socket.SOCK_STREAM))
socket.gaierror: [Errno -2] Name or service not known

Why?

The laptop is x86 (i.e., 32-bit) whereas the desktop is x86_64, but I'd be surprised if that mattered. The laptop also has two network interfaces (wireless and wired), whereas the desktop just has wired; again I doubt that's relevant. All three interfaces were bound to IPv6 addresses, according to "ifconfig". I diffed /etc/network on the two boxes, and saw no difference, except that the laptop has this clause

# The primary network interface
auto eth0
iface eth0 inet dhcp

... which, again, strikes me as irrelevant.

::

If you want some context: my Python program is trying to send email, and it's the email software that is ultimately calling getaddrinfo.


Check /etc/hosts on the box where it does not work. Is there an entry for localhost?
Also compare /etc/nsswitch.conf and see if there is anything suspicious, like missing 'hosts' line

0

精彩评论

暂无评论...
验证码 换一张
取 消