I'm developing a script in python that sends sms using a telnet connection to a portech mv-372.
The script works correctly but after some time the telnet connection drops and throws an "[Errno 32] Broken pipe" exception. As the script is running as a systemd service every time I find an error I end the script and systemd restarts it.
When the script reboots it goes into a loop because it can not connect to the modem over telnet. The script only reconnects when I reboot the modem.
Here's an excerpt 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 tcerminar the script I always close the onexao telnet using tn.close ().
Does anyone know why the link is blocked after the script finishes?