diff --git a/powerline/segments/common/wthr.py b/powerline/segments/common/wthr.py index 8819806f..38d7e4b3 100644 --- a/powerline/segments/common/wthr.py +++ b/powerline/segments/common/wthr.py @@ -139,11 +139,16 @@ class WeatherSegment(KwThreadedSegment): raw_response = urllib_read(url) if not raw_response: self.error('Failed to get response') - return + return None + response = json.loads(raw_response) - condition = response['query']['results']['weather']['rss']['channel']['item']['condition'] - condition_code = int(condition['code']) - temp = float(condition['temp']) + try: + condition = response['query']['results']['weather']['rss']['channel']['item']['condition'] + condition_code = int(condition['code']) + temp = float(condition['temp']) + except (KeyError, ValueError): + self.exception('Yahoo returned malformed or unexpected response: {0}', repr(raw_response)) + return None try: icon_names = weather_conditions_codes[condition_code]