0
I’m developing a python script that sends text using a telnet link to a portech mv-372.
The script works correctly but after some time the telnet connection drops and throws an exception "[Errno 32] Broken pipe". As the script is running as a systemd service whenever I encounter an error I finish the script and systemd restarts it.
When the script restarts it enters a loop because it cannot connect to the modem via telnet. The script only connects again when I reboot to the modem.
Here’s a copy of the code:
# Creare a Telnet Connection to Host1
try:
tn = telnetlib.Telnet(HOST)
sleep(1)
tn.read_until('username: ')
SendCommandToSocket(USERNAME, "password: ", 10, tn)
SendCommandToSocket(PASSWORD, "info.\r\n]", 10, tn)
print "Connection Established"
except Exception as e:
print e
logger.critical('Cannot connect to socket. Exception is: %s' %e)
tn.close()
sleep(10)
exit()
Before tying the script I always close the telnet onexao using Tn.close().
Can anyone tell me why the connection is blocked after the script is finished?