keptenkurk / BS440

Python code to talk to Medisana BS440 bluetooth enabled bathroom scale
MIT License
50 stars 34 forks source link

Occasional crash when sending e-mail #81

Closed keptenkurk closed 4 years ago

keptenkurk commented 6 years ago

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 4 years ago

Solved by handling a possible exception. Commit https://github.com/keptenkurk/BS440/commit/5483efc1dde9f2ff8e6adbcc497e778a626b18cb