SOCKET错误:[Errno 111]连接在Ubuntu上被拒绝

时间:2015-07-30 06:14:31

标签: python sockets smtp smtplib

Traceback (most recent call last):
   s = smtplib.SMTP('localhost')
  File "/usr/lib/python2.7/smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 311, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 286, in _get_socket
    return socket.create_connection((host, port), timeout)
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
socket.error: [Errno 111] Connection refused
问:我在我的ubuntu机器上收到此错误。问题是为什么呢? 原因是当我在Mac OS X 10.7上执行相同的代码时,我没有看到这个错误。我没有在Mac上做任何特殊配置来实现这一点。

1 个答案:

答案 0 :(得分:5)

确保您的系统正在运行smtp服务器:

netstat -nlt | grep '\<25\>'

如果你的系统正在运行smtp服务器,上面的命令会显示如下:

tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN