Skip to content

Commit

Permalink
add timeout to requests in text_from_image
Browse files Browse the repository at this point in the history
  • Loading branch information
dale-wahl committed Feb 1, 2023
1 parent 358697d commit 37eda2f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions processors/conversion/text_from_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,11 @@ def annotate_image(self, image_file):

with image_file.open("rb") as infile:
try:
api_request = requests.post(server.rstrip('/') + '/api/detect_text', files={'image': infile}, data=parameters)
except (requests.RequestException, ConnectionError) as e:
self.dataset.update_status("Skipping image %s: %s" % (image_file.name, str(e)))
return None
api_request = requests.post(server.rstrip('/') + '/api/detect_text', files={'image': infile}, data=parameters, timeout=30)
except requests.exceptions.ConnectionError as e:
message = f"Unable to establish connection to OCR server {e}; contact 4CAT administrator."
self.dataset.update_status(message)
raise ProcessorException(message)

if api_request.status_code != 200:
self.dataset.update_status("Got response code %i from DMI OCR server for image %s: %s" % (api_request.status_code, image_file.name, api_request.content))
Expand Down

0 comments on commit 37eda2f

Please sign in to comment.