Catch KeyError exception when interpreting json
authorAlexander Vasarab <alexander@wylark.com>
Tue, 2 Feb 2021 06:00:38 +0000 (22:00 -0800)
committerAlexander Vasarab <alexander@wylark.com>
Tue, 2 Feb 2021 06:00:38 +0000 (22:00 -0800)
infoex-autowx.py

index f2be003d5c792c62f3153a4d2b7ac4404e697eb0..9bd77c1f8315d1ad4528bd11859cad8eadeb3ae3 100755 (executable)
@@ -473,6 +473,9 @@ def get_mesowest_data(begin, end, station):
 
     try:
         observations = json['STATION'][0]['OBSERVATIONS']
 
     try:
         observations = json['STATION'][0]['OBSERVATIONS']
+    except KeyError:
+        LOG.error("Unexpected JSON in MesoWest response")
+        sys.exit(1)
     except ValueError:
         LOG.error("Bad JSON in MesoWest response")
         sys.exit(1)
     except ValueError:
         LOG.error("Bad JSON in MesoWest response")
         sys.exit(1)