Occasional crash when sending e-mail
Closed this issue · 1 comments
keptenkurk commented
I noticed that once every few weeks the application crashes. Added console logging which reveals it's a problem with sending the mail.
2018-03-17 09:30:04,540 INFO <module> Done receiving data from scale
Traceback (most recent call last):
File "BS440.py", line 318, in <module>
plugin.execute(config, persondata, weightdatasorted, bodydatasorted)
File "plugins/BS440mail.py", line 185, in execute
s = smtplib.SMTP(SmtpServer)
File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
return socket.create_connection((host, port), timeout)
File "/usr/lib/python2.7/socket.py", line 553, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known
In my setup the Pi is close to the scale and on WiFi. I Assume the problem is when it's trying to send mail but the network is not available at that time. gaierror points to being unable to resolve the name of the email server.
Maybe a solution would be to test network availability before going ahead...
keptenkurk commented
Solved by handling a possible exception. Commit 5483efc