Skip to content

Commit f31d8da

Browse files
update python-hand-text.md
update while condition to avoid infinite loop when retrieving the recognized text returns back {'status': 'NotStarted'} During the Polling, the API returns back {'status': 'NotStarted'} {'status': 'Running'} then if any error happens inside the API, the API returns back {'status': 'Failed'} otherwise the API returns back {'recognitionResult': {'lines': [...]}, 'status': 'Succeeded'}
1 parent cdb2607 commit f31d8da

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

articles/cognitive-services/Computer-vision/QuickStarts/python-hand-text.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,21 @@ operation_url = response.headers["Operation-Location"]
7575
# The recognized text isn't immediately available, so poll to wait for completion.
7676
import time
7777
analysis = {}
78-
while "recognitionResult" not in analysis:
78+
poll = True
79+
while (poll):
7980
response_final = requests.get(
8081
response.headers["Operation-Location"], headers=headers)
8182
analysis = response_final.json()
82-
time.sleep(1)
83+
if ("recognitionResult" in analysis):
84+
poll= False
85+
if ("status" in analysis and analysis['status'] == 'Failed'):
86+
poll= False
8387

84-
# Extract the recognized text, with bounding boxes.
85-
polygons = [(line["boundingBox"], line["text"])
86-
for line in analysis["recognitionResult"]["lines"]]
88+
polygons=[]
89+
if ("recognitionResult" in analysis):
90+
# Extract the recognized text, with bounding boxes.
91+
polygons = [(line["boundingBox"], line["text"])
92+
for line in analysis["recognitionResult"]["lines"]]
8793

8894
# Display the image and overlay it with the extracted text.
8995
from matplotlib.patches import Polygon

0 commit comments

Comments
 (0)