我有这段代码:
>>> import socket
>>> sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sck.connect(('loaclhost', 2525))
我有这个错误:
Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> sck.connect(('localhost', 2526)) socket.error: [Errno 10061] No connection could be made because
目标机器主动拒绝它
请帮助我。哪里可以出错?我该怎么修呢?
答案 0 :(得分:5)
尝试将连接更改为“localhost”而不是“loaclhost”
答案 1 :(得分:1)
您的代码和错误不匹配(localhost和端口号的拼写),但错误消息是由于没有服务器侦听该端口。下次剪切并粘贴确切的代码和错误消息。