Skip to content

Commit d4258fe

Browse files
committed
Handle the case when an image is unavailable
1 parent f522b6b commit d4258fe

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

otbox.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import base64
1919
import argparse
2020
import logging
21+
import sys
2122

2223
try:
2324
from PIL import Image
@@ -126,10 +127,19 @@ def _mqtt_handler_picturetoscreen(self, deviceType, deviceId, payload):
126127
{{TESTBED}}/deviceType/box/deviceId/box1/cmd/picturetoscreen
127128
'''
128129
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()
130+
try:
131+
image_url = json.loads(payload)['url']
132+
response = requests.get(image_url, stream=True)
133+
image = Image.open(response.raw)
134+
except IOError:
135+
# the image is not available now; skip this one
136+
print('image at {0} is not available, '.format(image_url)
137+
+ 'HTTP response code {0}'.format(res.status_code))
138+
sys.stdout.flush()
139+
else:
140+
image.thumbnail((480,320),Image.ANTIALIAS)
141+
self._otbox.change_image_queue.put(image)
142+
self._otbox.change_image_queue.join()
133143
return {}
134144

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

0 commit comments

Comments
 (0)