aws-samples / aws-samples/amazon-textract-textractor

Error No block for id using order_blocks_by_geo

Open
#214 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
493
Forks
163
PR merge metrics
No merged PRs in 30d

Description

We are getting below error while reading the AWS textract json output file and It is working for documents with 60 pages but it is failing for few documents with 4 & 8 pages

**Requirement:** To extract text from a scanned image pdf document using AWS
**Current Solution:** We are using AWS Textract service to convert scanned image pdf documents into text using amazon-textract-response-parser package

**Sample used code:**

from textractcaller.t_call import call_textract, Textract_Features 

s3Client = boto3.client("s3")

textractClient = boto3.client("textract", config=config)

def lambda_handler(event, context):
    try:
        # Load event into json format
        eventJson = json.loads(json.dumps(event))

        # Input file bucket name
        s3InputBucketName = eventJson["ConfigParameters"]["S3InputBucketName"] 

        # Input file name
        s3InputDocumentName = eventJson["ConfigParameters"]["S3InputDocumentName"]

        # Input file path
        s3InputDocumentPath = eventJson["ConfigParameters"]["S3InputDocumentPath"]
 
        # Pdf to json output bucket name
        s3PdfToJsonBucketName = eventJson["ConfigParameters"]["S3PdfToJsonBucketName"]
 
        # Json file name
        s3PdfToJsonFileName = s3InputDocumentName.split(".")[0] + ".json"

        # Call textract to convert pdf into json object
        jsonObject = call_textract(
            input_document=s3InputDocumentPath,
            features=[Textract_Features.FORMS, Textract_Features.TABLES],
            boto3_textract_client=textractClient,
            job_done_polling_interval=int(os.environ["JOB_POLLING_INTERVAL"]),
        )
except Exception as error:
raise

We have also tried below approach to get the full json after completing the AWS Textract job, however no luck and issue still persist
https://repost.aws/questions/QUXFfBPjryQWatuuSemwRNRg/textract-value-error-no-block-id

**Sample code:**
from textractcaller import get_full_json
def get_full_json(job_id: str = JobId,
textract_api: Textract_API = Textract_API.DETECT,
boto3_textract_client=textractClient)

**Error Message:**
{
   "errorMessage":"no block for id: 32a94a86-ad05-4ae4-8341-6730a8f53c7c",
   "errorType":"ValueError",
   "stackTrace":[
      "  File "/opt/python/lib/python3.8/site-packages/aws_lambda_powertools/tracing/tracer.py", line 305, in decoraten  response = lambda_handler(event, context, **kwargs)n",
      "  File ""/var/task/lambda_function.py"", line 397, in lambda_handlern    orderedDeserializeObject = order_blocks_by_geo(deserializeObject)n",
      "  File ""/opt/python/trp/t_pipeline.py"", line 18, in order_blocks_by_geon    r = t_document.relationships_recursive(page)n",
      "  File "/opt/python/trp/trp2.py", line 476, in relationships_recursiven    return set(self.__relationships_recursive(block=block))n",
      "  File "/opt/python/trp/trp2.py", line 471, in __relationships_recursiven    for child in self.__relationships_recursive(block=b):n",
      "  File "/opt/python/trp/trp2.py", line 471, in __relationships_recursiven    for child in self.__relationships_recursive(block=b):n",
      "  File "/opt/python/trp/trp2.py", line 467, in __relationships_recursiven    all_block = [self.get_block_by_id(id) for id in all_relations if id]n",
      "  File "/opt/python/trp/trp2.py", line 467, in n    all_block = [self.get_block_by_id(id) for id in all_relations if id]n",
      "  File "/opt/python/trp/trp2.py", line 461, in get_block_by_idn    raise ValueError(f"no block for id":{"id"}")"
   ]
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.