From 92717a3e11b5617ae394ebf72df3b9f2f5f7d65e Mon Sep 17 00:00:00 2001 From: Viswanathan Swaminathan Date: Thu, 6 Apr 2017 14:18:01 -0400 Subject: [PATCH 1/3] Adding exception handling when fetching the camera image to avoid python errors when host is not reachable or any url errors to camera --- homeassistant/components/camera/foscam.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/camera/foscam.py b/homeassistant/components/camera/foscam.py index a374d19f4d129..50bca78c6c3f3 100644 --- a/homeassistant/components/camera/foscam.py +++ b/homeassistant/components/camera/foscam.py @@ -66,9 +66,13 @@ def __init__(self, device_info): def camera_image(self): """Return a still image reponse from the camera.""" # Send the request to snap a picture and return raw jpg data - response = requests.get(self._snap_picture_url, timeout=10) - - return response.content + # Handle exception if host is not reachable or url failed + try: + response = requests.get(self._snap_picture_url, timeout=10) + except: + return None + else: + return response.content @property def name(self): From a9393756173aa433e419e74cc6128ecf8d55a43e Mon Sep 17 00:00:00 2001 From: Viswanathan Swaminathan Date: Thu, 6 Apr 2017 14:48:12 -0400 Subject: [PATCH 2/3] Added exception as ConnectionError instead of plain except --- homeassistant/components/camera/foscam.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/camera/foscam.py b/homeassistant/components/camera/foscam.py index 50bca78c6c3f3..2dc40a1268756 100644 --- a/homeassistant/components/camera/foscam.py +++ b/homeassistant/components/camera/foscam.py @@ -69,7 +69,7 @@ def camera_image(self): # Handle exception if host is not reachable or url failed try: response = requests.get(self._snap_picture_url, timeout=10) - except: + except requests.exceptions.ConnectionError as e: return None else: return response.content From 0678a392f633a5a7b2de994bdb3bb6f1a07f0764 Mon Sep 17 00:00:00 2001 From: Viswanathan Swaminathan Date: Thu, 6 Apr 2017 15:00:23 -0400 Subject: [PATCH 3/3] Added exception as ConnectionError instead of plain except. Removed the unused error handle --- homeassistant/components/camera/foscam.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/camera/foscam.py b/homeassistant/components/camera/foscam.py index 2dc40a1268756..c1f9513d2c69e 100644 --- a/homeassistant/components/camera/foscam.py +++ b/homeassistant/components/camera/foscam.py @@ -69,7 +69,7 @@ def camera_image(self): # Handle exception if host is not reachable or url failed try: response = requests.get(self._snap_picture_url, timeout=10) - except requests.exceptions.ConnectionError as e: + except requests.exceptions.ConnectionError: return None else: return response.content