Skip to content

Commit

Permalink
Added handling of HTTP status when requesting images
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisn committed Mar 13, 2024
1 parent d21c4c9 commit d3c5e8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 10 additions & 1 deletion lib/async_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import asyncore
import logging
import queue
import re
import socket
import threading
import urllib
Expand Down Expand Up @@ -95,7 +96,15 @@ def handle_expt(self):
def handle_close(self):
self.close()

self._client.http_received_data(self._data)
match = re.match(b'^HTTP/\d+\.\d+ (\d+)', self._header)
if match is not None:
status = int(match.group(1))
self.log("Response: HTTP status %d" % (status))

if status >= 200 and status <= 299:
self._client.http_received_data(self._data)
else:
self._client.http_closed()

self._header = None
self._data = b""
Expand Down
7 changes: 3 additions & 4 deletions lib/main_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,10 @@ def create_bitmap(self, image_data):

bitmap = None

try:
image = wx.Image(stream)
image = wx.Image(stream)
if image.IsOk():
bitmap = wx.Bitmap(image)
except wx.wxAssertionError as ex:
# Invalid image data.
else:
logging.warning("Couldn't create image")

return bitmap
Expand Down

0 comments on commit d3c5e8d

Please sign in to comment.