diff --git a/PogoOCR/cloudvision.py b/PogoOCR/cloudvision.py index aed03be..76910d4 100644 --- a/PogoOCR/cloudvision.py +++ b/PogoOCR/cloudvision.py @@ -18,5 +18,17 @@ def __init__(self, service_file, image_content=None, image_uri=None): def get_text(self): print("Requesting TEXT_DETECTION from Google Cloud API. This will cost us 0.0015 USD.") - response = self.google.text_detection(image=self.image, retry=5) - self.text_found = response.text_annotations + attempts = 0 + while attempts < 5: + attempts += 1 + response = self.google.text_detection(image=self.image) + try: + response.text_annotations[0] + except IndexError: + pass + else: + self.text_found = response.text_annotations + break + + if attempts == 5: + raise Exception(response.text_annotations)