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 get_weather() example #17

Closed nickbroon closed 5 years ago

nickbroon commented 5 years ago

Occasional traceback in weather example

Feb 25 17:17:46 raspberrypi weather.py[2043]: Traceback (most recent call last):
Feb 25 17:17:46 raspberrypi weather.py[2043]:   File "/home/pi/breakout-garden/examples/weather/weather.py", line 155, in <module>
Feb 25 17:17:46 raspberrypi weather.py[2043]:     weather = get_weather(location_string)
Feb 25 17:17:46 raspberrypi weather.py[2043]:   File "/home/pi/breakout-garden/examples/weather/weather.py", line 71, in get_weather
Feb 25 17:17:46 raspberrypi weather.py[2043]:     .join([str(c) for c in coords])))
Feb 25 17:17:46 raspberrypi weather.py[2043]: TypeError: 'NoneType' object is not iterable

My best guess is that perhaps get_coords() or the requests.get() may occasionally fail. Perhaps some try exception handling around these is needed?

nickbroon commented 5 years ago

Related traceback. Again probably due to failing to retrieve the weather.

Feb 28 09:12:17 raspberrypi weather.py[426]: Traceback (most recent call last):
Feb 28 09:12:17 raspberrypi weather.py[426]:   File "/home/pi/breakout-garden/examples/weather/weather.py", line 107, in
Feb 28 09:12:17 raspberrypi weather.py[426]:     weather = get_weather(location_string)
Feb 28 09:12:17 raspberrypi weather.py[426]:   File "/home/pi/breakout-garden/examples/weather/weather.py", line 76, in 
Feb 28 09:12:17 raspberrypi weather.py[426]:     weather["summary"] = curr[0].img["alt"].split()[0]
Feb 28 09:12:17 raspberrypi weather.py[426]: IndexError: list index out of range
nickbroon commented 5 years ago

Added the following diff:

diff --git a/examples/weather/weather.py b/examples/weather/weather.py
index 320455f..5878b52 100755
--- a/examples/weather/weather.py
+++ b/examples/weather/weather.py
@@ -5,6 +5,7 @@ import os
 import time
 import datetime
 import glob
+import logging

 from PIL import Image
 from PIL import ImageFont
@@ -15,6 +16,8 @@ import bme680
 from luma.core.interface.serial import i2c
 from luma.oled.device import sh1106

+logging.basicConfig(level=os.environ.get("LOGLEVEL", "WARNING"))
+
 try:
     import requests
 except ImportError:

and get this error that then leads to traceback.

Feb 28 15:05:36 raspberrypi weather.py[3135]: ERROR:geocoder.base:Status code Unknown from https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find: ERROR - HTTPSConnectionPool(host='geocode.arcgis.com', port=443): Read timed out. (read timeout=5.0)

So looks the code needs to deal with coords being None

Gadgetoid commented 5 years ago

I believe you fully patched this up in #10 - thank you!! Don't hesitate to re-open or pop up another issue if you have any other problems/suggestions.

nickbroon commented 5 years ago

Unfortunately it's not fully fixed. #10 just reduced the time frame during which it can happen. I think that's what needs is some exception handling (try ... except) around the url request calls to handle the case when they fail.