From 9254e7e862506ee8cd896d29c95d17c7b8360a1e Mon Sep 17 00:00:00 2001 From: viswa-swami Date: Fri, 7 Apr 2017 01:40:33 -0400 Subject: [PATCH] Foscam Camera: Adding exception handling when fetching the camera image to avoid python exception errors when host is not reachable or rather any url error to camera (#6964) * Adding exception handling when fetching the camera image to avoid python errors when host is not reachable or any url errors to camera * Added exception as ConnectionError instead of plain except * Added exception as ConnectionError instead of plain except. Removed the unused error handle --- 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 a374d19f4d1293..c1f9513d2c69ee 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 requests.exceptions.ConnectionError: + return None + else: + return response.content @property def name(self):