Python SOCKET 错误:[Errno 111] 连接被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20349170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SOCKET ERROR: [Errno 111] Connection refused
提问by Nishant Kashyap
I am using simple python lib for the SMTP But i am getting this error:
我正在为 SMTP 使用简单的 python lib 但我收到此错误:
import smtplib
smtpObj = smtplib.SMTP('localhost')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/smtplib.py", line 249, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 309, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 284, in _get_socket
return socket.create_connection((port, host), timeout)
File "/usr/lib/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 111] Connection refused
Using python-2.7
使用 python-2.7
回答by Yogesh dwivedi Geitpl
Start a simple SMTP server with Python like so:
使用 Python 启动一个简单的 SMTP 服务器,如下所示:
python -m smtpd -n -c DebuggingServer localhost:1025
or you can also try gmail smtp setting
或者您也可以尝试 gmail smtp 设置
server = smtplib.SMTP(host='smtp.gmail.com', port=587)
回答by Harshan Gowda
You need to Enable the Mode of Protocol you are using.Then it will create Bidirectional interaction virtual connection between your device and script. For Example the following script will require Telnet Mode to be Enabled so that it can call to another Device he is requesting for.
您需要启用您正在使用的协议模式。然后它将在您的设备和脚本之间创建双向交互虚拟连接。例如,以下脚本需要启用 Telnet 模式,以便它可以调用他请求的另一个设备。
telA = connect(a)
telA = 连接(一)
telA.write("xcom Dial Number:[email protected]\n")
time.sleep(10)
quit_telnet(telA)
print telA.read_all()
回答by andilabs
if you:
如果你:
python -m smtpd -n -c DebuggingServer localhost:1025
as suggested by Allen Thomas, then make sure you init:
按照 Allen Thomas 的建议,然后确保您初始化:
server = smtplib.SMTP(host='localhost', port=1025)
with matching port number, here: 1025.
具有匹配的端口号,这里是:1025。

