Skip to content

Commit c848678

Browse files
committed
Handle the case when an image is unavailable
1 parent feba023 commit c848678

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

otbox.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,19 @@ def _mqtt_handler_picturetoscreen(self, deviceType, deviceId, payload):
126126
{{TESTBED}}/deviceType/box/deviceId/box1/cmd/picturetoscreen
127127
'''
128128
assert deviceType==DEVICETYPE_BOX
129-
image = Image.open(requests.get(json.loads(payload)['url'], stream=True).raw)
130-
image.thumbnail((480,320),Image.ANTIALIAS)
131-
self._otbox.change_image_queue.put(image)
132-
self._otbox.change_image_queue.join()
129+
try:
130+
image_url = json.loads(payload)['url']
131+
response = requests.get(image_url, stream=True)
132+
image = Image.open(response.raw)
133+
except IOError:
134+
# the image is not available now; skip this one
135+
print('image at {0} is not available, '.format(image_url)
136+
+ 'HTTP response code {0}'.format(response.status_code))
137+
sys.stdout.flush()
138+
else:
139+
image.thumbnail((480,320),Image.ANTIALIAS)
140+
self._otbox.change_image_queue.put(image)
141+
self._otbox.change_image_queue.join()
133142
return {}
134143

135144
def _mqtt_handler_colortoscreen(self, deviceType, deviceId, payload):

0 commit comments

Comments
 (0)