SOCKET ERROR: [Errno 111] Connection refused on Ubuntu

一世执手 提交于 2019-12-22 09:45:27

问题


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

Q: I am getting this error on my ubuntu machine. Question is why so? The reason being when I execute the same code on Mac OS X 10.7 I don't see this error. And I did not do any special configuration on Mac for this to work.


回答1:


Make sure that your system is running smtp server:

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

If your system is running the smtp server, the above command will show somehting like this:

tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN     


来源:https://stackoverflow.com/questions/31716349/socket-error-errno-111-connection-refused-on-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!