pimoroni / breakout-garden

Documentation, software, and examples for the Breakout Garden ecosystem.
https://shop.pimoroni.com/products/breakout-garden-hat
MIT License
70 stars 13 forks source link

Traceback in weather example #19

Closed nickbroon closed 5 years ago

nickbroon commented 5 years ago

Occasional traceback in the get_weather function

Mar 11 10:14:22 raspberrypi weather.py[2437]: Traceback (most recent call last):
Mar 11 10:14:22 raspberrypi weather.py[2437]:   File "/home/pi/breakout-garden/examples/weather/weather.py", line 164, in <module>
Mar 11 10:14:22 raspberrypi weather.py[2437]:     weather_icon = get_weather_icon(get_weather(coords))
Mar 11 10:14:22 raspberrypi weather.py[2437]:   File "/home/pi/breakout-garden/examples/weather/weather.py", line 80, in get_weather
Mar 11 10:14:22 raspberrypi weather.py[2437]:     weather["summary"] = curr[0].img["alt"].split()[0]
Mar 11 10:14:22 raspberrypi weather.py[2437]: IndexError: list index out of range
Mar 11 10:14:23 raspberrypi systemd[1]: weather-oled.service: Main process exited, code=exited, status=1/FAILURE

I'd guess that try/except is needed round the call to request.get() call in the case in intermittent network error and also a check performed that soup.findall() that it actually finds something that can then be split.

nickbroon commented 5 years ago

Different traceback in the same area, this time from the request.get() call

Mar 11 17:22:02 raspberrypi weather.py[19950]: Traceback (most recent call last):
Mar 11 17:22:02 raspberrypi weather.py[19950]:   File "/home/pi/breakout-garden/examples/weather/weather.py", line 164, 
Mar 11 17:22:02 raspberrypi weather.py[19950]:     weather_icon = get_weather_icon(get_weather(coords))
Mar 11 17:22:02 raspberrypi weather.py[19950]:   File "/home/pi/breakout-garden/examples/weather/weather.py", line 76, i
Mar 11 17:22:02 raspberrypi weather.py[19950]:     .join([str(c) for c in coords])))
Mar 11 17:22:02 raspberrypi weather.py[19950]:   File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 75,
Mar 11 17:22:02 raspberrypi weather.py[19950]:     return request('get', url, params=params, **kwargs)
Mar 11 17:22:02 raspberrypi weather.py[19950]:   File "/usr/local/lib/python2.7/dist-packages/requests/api.py", line 60,
Mar 11 17:22:02 raspberrypi weather.py[19950]:     return session.request(method=method, url=url, **kwargs)
Mar 11 17:22:02 raspberrypi weather.py[19950]:   File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", lin
Mar 11 17:22:02 raspberrypi weather.py[19950]:     resp = self.send(prep, **send_kwargs)
Mar 11 17:22:02 raspberrypi weather.py[19950]:   File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", lin
Mar 11 17:22:02 raspberrypi weather.py[19950]:     r = adapter.send(request, **kwargs)
Mar 11 17:22:02 raspberrypi weather.py[19950]:   File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", lin
Mar 11 17:22:02 raspberrypi weather.py[19950]:     raise ConnectionError(e, request=request)
Mar 11 17:22:02 raspberrypi weather.py[19950]: requests.exceptions.ConnectionError: HTTPSConnectionPool(host='darksky.ne
Mar 11 17:22:03 raspberrypi systemd[1]: weather-oled.service: Main process exited, code=exited, status=1/FAILURE