Skip to content

sample_recognize_receipts.py should have a check before print items in receipt #19341

@squassina

Description

@squassina
  • Package Name: sample_recognize_receipts.py and sample_recognize_receipts_from_url.py
  • Package Version: Current
  • Operating System: Any
  • Python Version: 3.9

Describe the bug
If the receipt is not itemized an error is display in the sample

To Reproduce
Steps to reproduce the behavior:

  1. have a receipt without items
  2. run python sample_recognize_receipts.py on that receipt

Expected behavior
The program should complete successfully even without items.

Screenshots

This is the output of a run of the sample in one document I have:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-84af238b6b50> in <module>
----> 1 PrintReceipt(receipt_lst[6])

<ipython-input-20-09663b52ec70> in PrintReceipt(receipts)
     13         print("Receipt items:")
     14 #        if receipt.fields.get("Items"):
---> 15         for idx, item in enumerate(receipt.fields.get("Items").value):
     16             print("...Item #{}".format(idx+1))
     17             item_name = item.value.get("Name")

AttributeError: 'NoneType' object has no attribute 'value'

Additional context
None.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions