I have been making a tool for connecting to telnet, but when I try to connect to telnet using user-defined function, I got an error. What is the difference between these 2 codes? why does the second code make an error?
1. code without error
import os, time, re, telnetlib
from time import sleep
if __name__ == '__main__':
HOST = 'localhost'
PORT = 14440
cm_path = 'C:/bin'
os.chdir(cm_path)
tn = telnetlib.Telnet(HOST, PORT)
2. code with error
import os, time, re, telnetlib
from time import sleep
def myTelnet(path, host, port):
os.chdir(path)
tn = telnetlib.Telnet(host, port)
if __name__ == '__main__':
HOST = 'localhost'
PORT = 14440
cm_path = 'C:/bin'
tn = myTelnet(cm_path,HOST,PORT)
After running the code 2, I got the error message below:
ConnectionRefusedError: [WinError 10061] \u5bfe\u8c61\u306e\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u306b\u3088\u3063\u3066\u62d2\u5426\u3055\u308c\u305f\u305f\u3081\u3001\u63a5\u7d9a\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002