Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
Fix retry bug
Browse files Browse the repository at this point in the history
Has been reported at googleapis/python-vision#31
  • Loading branch information
Jay Turner committed Jun 28, 2020
1 parent 9d02a16 commit 19fd198
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions PogoOCR/cloudvision.py
Expand Up @@ -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)

0 comments on commit 19fd198

Please sign in to comment.