0

Working on my first python script at work to automate some testing.

I'm having trouble telneting to a server twice from my script. The first time I'm calling the telnet function, everything works, the second time my script calls the telnet function, I get the following errors below. I have a second function that runs some commands and exits. I've also tried without an exit, but that did not work either. So I thought that would close out the session, by doing a "close" on the session as well.

Thanks in advance.

The reason I want to go back into the server, is I make a change to the DB and want to verify the change took affect.

I'm calling these functions from another python script.

** Updated with where "tn" is assigned, which is outside the function, so I'm unsure how telnet even works the first time.

tn = telnetlib.Telnet(intems03, "8123")

def telnet_ems():
    tn.read_until(b"Login   :")
    tn.write(bytes(username + "\n", "UTF-8"))
    tn.read_until(b"Password:")
    tn.write(bytes(password + "\n", "UTF-8"))

def show_sip_domain(sipDomain):
    str2byte = sipDomain.encode("ascii")
    tn.write(b"show Sip_Domain Sip_Domain_Id "+str2byte)
    tn.write(b"\n")
    tn.write(b"exit\n")

** Error messages **

Traceback (most recent call last):

File "c:\Users\xxxx\.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\ptvsd_launcher.py", line 43, in <module> main(ptvsdArgs)

File "c:\Users\xxxx\.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\lib\python\ptvsd\__main__.py", line 432, in main run()

File "c:\Users\xxxx\.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\lib\python\ptvsd\__main__.py", line 316, in run_file runpy.run_path(target, run_name='__main__')

File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname)

File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name)

File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\runpy.py", line 85, in _run_code exec(code, run_globals)

File "c:\Python_Exercises\Selenium_test_examples\test_TelnetEms.py", line 11, in <module> telnet_ems()

File "c:\Python_Exercises\Selenium_test_examples\Telnet_EMS_Show_functions.py", line 16, in telnet_ems tn.read_until(b"Login :")
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\telnetlib.py", line 315, in read_until self.fill_rawq()

File "C:\Users\xxxx\AppData\Local\Programs\Python\Python37-32\lib\telnetlib.py", line 524, in fill_rawq buf = self.sock.recv(50)

ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

1 Answers1

0

Error 10053 is telling you that the other end is telling you to get lost, though I'm not sure we have enough context to know what's going on.

One thing to check: after you run the first one that works, see if there is still a TCP connection from the python-hosted computer to whatever it's talking to; you can find this at the command line (Linux or Windows, at least), with the netstat command: if you still have a lingering connection, you for sure have to close the old one with .close()

Also, is there a delay before you get the above message, indicating it might be timing out, or does it happen immediately?

[Disclaimer: network guy, not a python guy]

Steve Friedl
  • 3,929
  • 1
  • 23
  • 30
  • With some editing, my co-worker got the script to work on a linux box. I'm trying to run it from Windows. Hmm, now I have to troubleshoot windows.. – Tonkers303 Aug 28 '19 at 19:06
  • Can you share the nature of the changes such that we can understand what was going wrong? – Steve Friedl Aug 28 '19 at 19:16
  • He move the tn assignment to the first script, and assigned it before each telnet_ems() call, passing the tn param for each function call. – Tonkers303 Aug 28 '19 at 19:44
  • 1
    Oh I also did check, I see the TCP drop before the second telnet tries to establish. – Tonkers303 Aug 28 '19 at 20:26