Python Telnet 简单测试以连接被拒绝而告终
Python Telnet simple test ends up with a connection refused
6 个多小时以来,我一直遇到同样的错误,我的简单 telnet python 代码无法正常工作,即使它简单得可笑。
我正在使用 Python 2.7.10
在这里。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import telnetlib
HOST = "192.168.1.10"
tn = telnetlib.Telnet(HOST)
tn.write("Message for the receiver \n")
tn.read_until("\n")
我尝试了很多不同的代码,所有 return 这些错误:
Traceback (most recent call last):
File "runsimple.py", line 8, in <module>
tn = telnetlib.Telnet(HOST)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/telnetlib.py", line 211, in __init__
self.open(host, port, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/telnetlib.py", line 227, in open
self.sock = socket.create_connection((host, port), timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection
raise err
socket.error: [Errno 61] Connection refused
我尝试连接的 IP 是正确的,并且是开放的,因为它是一个微型简单的服务器。目的是发送一些字符串到这个服务器,让他读取。
我现在测试了在 Whosebug 上找到的几乎所有解决方案,所有解决方案都会导致此类错误。
如果有人遇到同样的问题/知道是什么原因,那将对我有很大帮助..
非常感谢..我没有更多的帮助,因为它是一个非常简单的代码...
您的服务器使用了非标准端口号。尝试在客户端指定端口号:
tn = telnetlib.Telnet(HOST, 5555)
注意:端口号指定为实际数字,而不是字符串。请不要 "
- 在数字周围加上引号。
6 个多小时以来,我一直遇到同样的错误,我的简单 telnet python 代码无法正常工作,即使它简单得可笑。
我正在使用 Python 2.7.10 在这里。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import telnetlib
HOST = "192.168.1.10"
tn = telnetlib.Telnet(HOST)
tn.write("Message for the receiver \n")
tn.read_until("\n")
我尝试了很多不同的代码,所有 return 这些错误:
Traceback (most recent call last):
File "runsimple.py", line 8, in <module>
tn = telnetlib.Telnet(HOST)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/telnetlib.py", line 211, in __init__
self.open(host, port, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/telnetlib.py", line 227, in open
self.sock = socket.create_connection((host, port), timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection
raise err
socket.error: [Errno 61] Connection refused
我尝试连接的 IP 是正确的,并且是开放的,因为它是一个微型简单的服务器。目的是发送一些字符串到这个服务器,让他读取。
我现在测试了在 Whosebug 上找到的几乎所有解决方案,所有解决方案都会导致此类错误。
如果有人遇到同样的问题/知道是什么原因,那将对我有很大帮助..
非常感谢..我没有更多的帮助,因为它是一个非常简单的代码...
您的服务器使用了非标准端口号。尝试在客户端指定端口号:
tn = telnetlib.Telnet(HOST, 5555)
注意:端口号指定为实际数字,而不是字符串。请不要 "
- 在数字周围加上引号。