diff --git a/otbox.py b/otbox.py index 23b54f6..12e22a9 100644 --- a/otbox.py +++ b/otbox.py @@ -126,10 +126,19 @@ def _mqtt_handler_picturetoscreen(self, deviceType, deviceId, payload): {{TESTBED}}/deviceType/box/deviceId/box1/cmd/picturetoscreen ''' assert deviceType==DEVICETYPE_BOX - image = Image.open(requests.get(json.loads(payload)['url'], stream=True).raw) - image.thumbnail((480,320),Image.ANTIALIAS) - self._otbox.change_image_queue.put(image) - self._otbox.change_image_queue.join() + try: + image_url = json.loads(payload)['url'] + response = requests.get(image_url, stream=True) + image = Image.open(response.raw) + except IOError: + # the image is not available now; skip this one + print('image at {0} is not available, '.format(image_url) + + 'HTTP response code {0}'.format(response.status_code)) + sys.stdout.flush() + else: + image.thumbnail((480,320),Image.ANTIALIAS) + self._otbox.change_image_queue.put(image) + self._otbox.change_image_queue.join() return {} def _mqtt_handler_colortoscreen(self, deviceType, deviceId, payload):